XLL+ Class Library

Using the Microsoft Foundation Classes

AppWizard - MFC option

If you want to use the Microsoft Foundation Classes in your add-in, you must select the MFC option in the AppWizard when you create your project.

 
AppWizard under Visual Studio 6
 
 
AppWizard under Visual Studio .NET or Visual Studio 2005

The effects of setting this option are:

As a result, you are able to use MFC classes and methods from within your XLL. (Note, however, that the Document/View framework is not available from an XLL.)

Programming for MFC DLLs

Programmers familiar with writing DLLs using MFC will know that certain internal MFC data structures must be initialised whenever they are used in a DLL. In standard MFC, the AFX_MANAGE_STATE macro is used for this purpose. In an XLL+ library, you should use the XLL_FIX_STATE macro.

What this means is that you must place the XLL_FIX_STATE macro in every add-in function that uses any MFC features.

CExcelWnd

The CExcelWnd class acts as a link between Excel and MFC. Create a CExcelWnd object, and it will act as an MFC CWnd, corresponding to the Excel application window. You can use this object as a parent for any MFC windows and other objects you need to create.

Next: Calling MFC methods >>