Export (0) Print
Expand All
TRY
Expand Minimize

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

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

See Also

MFC Macros and Globals| AfxTermExtensionModule

Show:
© 2014 Microsoft