Export (0) Print
Expand All
MFC
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  
);

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.

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

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:

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

Header: afxdll_.h

Community Additions

ADD
Show:
© 2014 Microsoft