AFX_EXTENSION_MODULE Structure
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at AFX_EXTENSION_MODULE Structure.
The AFX_EXTENSION_MODULE
is used during initialization of MFC extension DLLs to hold the state of extension DLL module.
Syntax
struct AFX_EXTENSION_MODULE
{
BOOL bInitialized;
HMODULE hModule;
HMODULE hResource;
CRuntimeClass* pFirstSharedClass;
COleObjectFactory* pFirstSharedFactory;
};
Parameters
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.
Remarks
MFC extension DLLs need to do two things in their DllMain
function:
Call AfxInitExtensionModule and check the return value.
Create a CDynLinkLibrary object if the DLL will be exporting CRuntimeClass objects or has its own custom resources.
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 NVC_MFC_DLLDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("NVC_MFC_DLL.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(NVC_MFC_DLLDLL, hInstance))
return 0;
The module information stored in the AFX_EXTENSION_MODULE
structure can be copied into the CDynLinkLibrary object. For example:
IMPLEMENT_DYNAMIC(CMyDynLinkLibrary, CDynLinkLibrary)
CMyDynLinkLibrary::CMyDynLinkLibrary(AFX_EXTENSION_MODULE& state, BOOL bSystem)
: CDynLinkLibrary(state, 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;
}
Requirements
Header: afx.h
See Also
Structures, Styles, Callbacks, and Message Maps
AfxInitExtensionModule
AfxTermExtensionModule