This documentation is archived and is not being maintained.


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

BOOL AFXAPI AfxInitExtensionModule(
   HMODULE hModule 



A reference to the AFX_EXTENSION_MODULE 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.


A handle of the extension DLL module.

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

For example:

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
   if (dwReason == DLL_PROCESS_ATTACH)
      // Extension DLL one-time initialization
      if (!AfxInitExtensionModule(extensionDLL, 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:

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).