An add-in will often need to contain data that has application-level scope. For example, an add-in might have a connection to a database that is only open as long as the add-in is in use.
XLL+ projects include a single instance of a class descended from CXllApp. This class and all its code is generated initially by the AppWizard when the project is created.
The CXllApp object represents the add-in library. It is in existence for as long as the library is open, and its lifetime ends when the add-in is closed.
It is the obvious place to keep data and objects that must exist at application scope.
You can get a pointer to your CXllApp instance at any time by calling the function XllGetApp().
Note: If you are using the MFC build of XLL+, you must use the macro XLL_FIX_STATE before using any data held in your CXllApp class.)
CXllApp has a number of events which you can trap by implementing virtual functions. The table below lists the more important events.
Event | Description |
---|---|
OnXllOpenEx | Called by the framework when Excel opens the XLL. The overridden function can return FALSE to halt further loading of the XLL. |
OnXllClose | Called by the framework when Excel closes the XLL |
OnXllRegister | Called by the framework when the add-in is registered with the Excel Add-in Manager |
OnXllUnregister | Called by the framework when the add-in is removed from the list of add-ins with the Excel Add-in Manager |