Partager via


AfxInitExtensionModule

Call this function in an extension DLL's DllMain to initialize the DLL.

BOOL AFXAPI AfxInitExtensionModule( 
   AFX_EXTENSION_MODULE& state, 
   HMODULE hModule  
);

Parameters

  • state
    A reference to the AFX_EXTENSION_MODULE Structure structure that will contain the state of the extension DLL module after the initialization. The state includes 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.

  • hModule
    A handle of the extension DLL module.

Return Value

TRUE if the extension DLL is successfully initialized; otherwise, FALSE.

Remarks

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;

AfxInitExtensionModule makes a copy of the DLL's HMODULE and captures the DLL's runtime-classes (CRuntimeClass structures) as well as its object factories (COleObjectFactory objects) for use later when the CDynLinkLibrary object is created.

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 Structure objects or has its own custom resources.

You can call AfxTermExtensionModule to clean up the extension DLL when each process detaches from the extension DLL (which happens when the process exits, or when the DLL is unloaded as a result of an AfxFreeLibrary call).

Requirements

Header: afxdll_.h

See Also

Reference

AfxTermExtensionModule

Concepts

MFC Macros and Globals