AfxTermExtensionModule

void AFXAPI AfxTermExtensionModule( AFX_EXTENSION_MODULE& state, BOOL bAll = FALSE );

Parameters

state

A reference to the AFX_EXTENSION_MODULE structure that contains the state of extension DLL module.

bAll   If TRUE, cleanup all extension DLL modules. Otherwise, cleanup only the current DLL module.

Remarks

Call this function to allow MFC to cleanup the extension DLL when each process detaches from the DLL (which happens when the process exits, or when the DLL is unloaded as a result of a AfxFreeLibrary call). AfxTermExtensionModule will delete any local storage attached to the module and remove any entries from the message map cache. For example:

static AFX_EXTENSION_MODULE extensionDLL;
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;
      // TODO: perform other initialization tasks here
   }
   else if (dwReason == DLL_PROCESS_DETACH)
   {
      // Extension DLL per-process termination
      AfxTermExtensionModule(extensionDLL);
     // TODO: perform other cleanup tasks here
   }
   return 1;   // ok
}

If your application loads and frees extension DLLs dynamically, be sure to call AfxTermExtensionModule. Since most extension DLLs are not dynamically loaded (usually, they are linked via their import libraries), the call to AfxTermExtensionModule is usually not necessary.

MFC extension DLLs need to call AfxInitExtensionModule in their DllMain. If the DLL will be exporting CRuntimeClass objects or has its own custom resources, you also need to create a CDynLinkLibrary object in DllMain.

See Also   AfxInitExtensionModule