in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Excel add in development in C++ Aplications in finance - Dalton S.

Dalton S. Excel add in development in C++ Aplications in finance - Wiley publishing , 2005. - 425 p.
ISBN 0-470-02469-0
Download (direct link): exceladdindevelopmentincand2005.pdf
Previous << 1 .. 50 51 52 53 54 55 < 56 > 57 58 59 60 61 62 .. 168 >> Next

5. It should provide a clean way to convert between xlopers and supported OLE/COM variants.
6. It should provide a method for obtaining a pointer to a static xloper that can be returned to Excel. It should, at the same time, clean up the resources associated with the cpp_xloper, and handle any signalling to Excel about memory that still needs to be freed.
2 There is, at the time of writing, a C++ wrapper called XLW developed by Jérôme Lecomte which can be accessed via the Source Forge website at A review of this open source project is beyond the scope of this book, other than to say that it wraps more than just the Excel data structures: it also wraps access to many of the C API functions. It is well worth looking at, if only to see the variety of approaches and resources that can be employed.
Passing Data between Excel and the DLL
The cpp_xloper class (included in the CD ROM) is a fairly thin skin to the xloper,
exposing the following types of member functions:
• A number of constructor member functions, one for each of the types of xloper that one regularly needs in this context.
• A number of assignment functions, to change the type or value of an xloper.
• A number of type conversion operator functions that simplify the copying of an xloper's value to a simple C/C++ variable type.
• A number of functions that simplify the getting and setting of values within an xltypeMulti array.
• An overloaded address of operator (&) for the address of the xloper, and a function that returns the address of the cpp_xloper object to compensate for the hijacking of ‘&’.
• Some simple private functions that are self-explanatory.
The class contains some private data members:
• The xloper, m_Op.
• A Boolean, m_RowByRowArray, that determines if xltypeMulti arrays have their elements stored row-by-row or not.
• A Boolean, m_DLLtoFree, that determines if any memory pointed to by the xloper was dynamically allocated by the DLL. (This is set during construction or assignment and referred to during destruction or reassignment.)
• A Boolean, m_XLtoFree, that determines if any memory pointed to by the xloper was dynamically allocated by Excel. (This must be set using the SetExceltoFree() method, as the class has no way of knowing automatically. It is referred to during destruction or reassignment.)
Here is a listing of the header file cpp_xloper.h:
#include "xlcall.h"
#include "xloper.h"
class cpp_xloper {
// constructors
cpp_xloper(); // created as xltypeMissing
cpp_xloper(xloper *p_oper); // contains copy of given xloper cpp_xloper(char *text); // xltypeStr
cpp_xloper(int w); // xltypeInt
cpp_xloper(int w, int min, int max); // xltypeInt (or xltypeMissing)
cpp_xloper(double d); // xltypeNum
cpp_xloper(bool b); // xltypeBool
cpp_xloper(WORD e); // xltypeErr
cpp_xloper(WORD, WORD, BYTE, BYTE); // xltypeSRef
cpp_xloper(char *, WORD, WORD, BYTE, BYTE); // xltypeRef from sheet name cpp_xloper(DWORD, WORD, WORD, BYTE, BYTE); // xltypeRef from sheet ID cpp_xloper(VARIANT *pv); // Takes its type from the VARTYPE
Excel Add-in Development in C/C++
// xltypeMulti constructors
cpp_xloper(WORD rows, WORD cols); // array of undetermined type cpp_xloper(WORD rows, WORD cols, double *d_array); // array of xltypeNum cpp_xloper(WORD rows, WORD cols, char **str_array); // xltypeStr array cpp_xloper(WORD &rows, WORD &cols, xloper *input_oper); // from SRef/Ref cpp_xloper(WORD rows, WORD cols, cpp_xloper *init_array); cpp_xloper(xl_array *array);
cpp_xloper(cpp_xloper &source); // Copy constructor
// destructor
// Overloaded operators
cpp_xloper &operator=(const cpp_xloper &source); void operator=(int); // xltypeInt
void operator=(bool b); // xltypeBool
void operator=(double); // xltypeNum
void operator=(WORD e); // xltypeErr
void operator=(char *); // xltypeStr
void operator=(xloper *); // same type as passed-in xloper
void operator=(VARIANT *); // same type as passed-in Variant
void operator=(xl_array *array);
bool operator==(cpp_xloper &cpp_op2);
bool operator==(int w);
bool operator==(bool b);
bool operator==(double d);
bool operator==(WORD e);
bool operator==(char *text);
bool operator==(xloper *);
bool operator!=(cpp_xloper &cpp_op2);
bool operator!=(int w);
bool operator!=(bool b);
bool operator!=(double d);
bool operator!=(WORD e);
bool operator!=(char *text);
bool operator!=(xloper *);
void operator++(void);
void operator--(void);
operator int(void);
operator bool(void);
operator double(void);
operator char *(void);
xloper *operator&() {return &m_Op;} // return xloper address
Previous << 1 .. 50 51 52 53 54 55 < 56 > 57 58 59 60 61 62 .. 168 >> Next