XLL+ Class Library

::XLL_FIX_STATE

Ensure that global data is in scope (MFC calls only)

[C++]
XLL_FIX_STATE();

Remarks

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.

STL libraries

Note - this macro is required only for add-ins built using MFC. It is not required for add-ins that only use the STL libraries. In the STL build the macro is defined as empty. However, if you are writing reusable code that may later be included in an MFC project, then you should use the macro as instructed above.

Requirements

Header: xllplus.h

See Also

Global functions & macros | Function attribute: appscope | Uses Application-level Data command