XLL+ Class Library (7.0)

::XLL_FIX_STATE

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

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() will only succeed within the scope of an XLL_FIX_STATE macro.

Exceptions

All add-in functions generated by XLL+ version 6 have an instance of XLL_FIX_STATE in their outer "shell" function. There is therefore no requirement for the add-in function to have its own XLL_FIX_STATE.

The following virtual functions are always called within the scope of XLL_FIX_STATE, and thus do not need their own instance of XLL_FIX_STATE.

CXllApp::InitInstance
CXllApp::ExitInstance
CXllApp::OnXllRegister
CXllApp::OnXllRegisterEx
CXllApp::OnXllUnregister
CXllApp::OnXllLoad
CXllApp::OnXllUnload
CXllApp::OnXllOpen
CXllApp::OnXllOpenEx
CXllApp::OnXllClose

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