The AFX_EXTENSION_MODULE structure has the following form:
struct AFX_EXTENSION_MODULE
{
BOOL bInitialized;
HMODULE hModule;
HMODULE hResource;
CRuntimeClass* pFirstSharedClass;
COleObjectFactory* pFirstSharedFactory;
};
The AFX_EXTENSION_MODULE is used during initialization of MFC extension DLLs to hold the state of extension DLL module.
Members
bInitialized
TRUE if the DLL module has been initialized with AfxInitExtensionModule.
hModule
Specifies the handle of the DLL module.
hResource
Specifies the handle of the DLL custom resource module.
pFirstSharedClass
A pointer to information (the CRuntimeClass structure) about the DLL module's first runtime class. Used to provide the start of the runtime class list.
pFirstSharedFactory
A pointer to the DLL module's first object factory (a COleObjectFactory object). Used to provide the start of the class factory list.
Comments
MFC extension DLLs need to do two things in their DllMain function:
The AFX_EXTENSION_MODULE structure is used to hold a copy of the extension DLL module state, including a copy of the runtime class objects that have been initialized by the extension DLL as part of normal static object construction executed before DllMain is entered. For example:
static AFX_EXTENSION_MODULE extensionDLL;
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
// initialize this DLL's extension module
VERIFY(AfxInitExtensionModule(extensionDLL, hInstance));
The module information stored in the AFX_EXTENSION_MODULE structure can be copied into the CDynLinkLibrary object. For example:
// CDynLinkLibrary class
IMPLEMENT_DYNAMIC(CDynLinkLibrary, CCmdTarget)
// Constructor
CDynLinkLibrary::CDynLinkLibrary(AFX_EXTENSION_MODULE& state, BOOL bSystem)
{
#ifndef _AFX_NO_OLE_SUPPORT
m_factoryList.Construct(offsetof(COleObjectFactory, m_pNextFactory));
#endif
m_classList.Construct(offsetof(CRuntimeClass, m_pNextClass));
// copy info from AFX_EXTENSION_MODULE struct
ASSERT(state.hModule != NULL);
m_hModule = state.hModule;
m_hResource = state.hResource;
m_classList.m_pHead = state.pFirstSharedClass;
#ifndef _AFX_NO_OLE_SUPPORT
m_factoryList.m_pHead = state.pFirstSharedFactory;
#endif
m_bSystem = bSystem;
See Also AfxInitExtensionModule, AfxTermExtensionModule