XLL+ Class Library

CXllApp Class

[C++]
class CXllApp

Overview

The CXllApp class is descended from CWinApp. Your implementation class, which is generated by the XLL Plus AppWizard, is in turn descended from CXllApp.

The CXllApp class implements most of the functionality necessary for a DLL to be accepted by Excel as an add-in library.

One and only one instance of CXllApp exists in any XLL. You can retrieve a pointer to it using the XllGetApp() global function. This call is only valid within the scope of an XLL_FIX_STATE macro (see below).

You can use your derived application class as a place to store data that must have a lifetime as long as that of the library (i.e. 'global' data). Database connections, logon details and performance statistics all fall into this category, and can usefully be stored in the application object.

Data that lives in the application class exists once for each instance of the library. Thus, if you have three instances of Excel using the add-in, you will have three separate copies of the data contained in the application class.

XLL_FIX_STATE

When Excel calls an add-in function, the static data structures which lie at the heart of the Microsoft Foundation Classes (MFC) are not yet properly initialised. It is necessary to ensure that MFC's static pointers are pointing to the frame of reference of the XLL.

The XLL_FIX_STATE macro achieves this. An instance of this macro will ensure the correct state of all MFC variables within the same scope as the macro. In particular calls to AfxGetApp() (or to XllGetApp(), which calls it) will only succeed within the scope of an XLL_FIX_STATE macro.

If you do not intend to use MFC, you can safely omit the XLL_FIX_STATE macro.

Requirements

Header: xllplus.h

See Also

CXllApp Methods | xllplus.h | CXllFn object