Share via


Initialize Regular DLLs

OverviewHow Do IFAQDetailsSample

Because regular DLLs have a CWinApp object, they should perform their initialization and termination tasks in the same location as an MFC application: in the InitInstance and ExitInstance member functions of the DLL’s CWinApp-derived class. Because MFC provides a DllMain function that is called by _DllMainCRTStartup for PROCESS_ATTACH and PROCESS_DETACH, you should not write your own DllMain function. The MFC-provided DllMain function calls InitInstance when your DLL is loaded and it calls ExitInstance before the DLL is unloaded.

A regular DLL can keep track of multiple threads by calling and in its InitInstance function. These functions allow the DLL to track thread-specific data.

In your regular DLL that dynamically links to MFC, if you are using any MFC OLE, MFC Database (or DAO), or MFC Sockets support, respectively, the MFC debug extension DLLs MFCOxxD.DLL, MFCDxxD.DLL, and MFCNxxD.DLL (where xx is the version number) are linked in automatically. You must call one of the following predefined initialization functions for each of these DLLs that you are using in your regular DLL's CWinApp::InitInstance.

Type of MFC Support Initialization Function to Call
MFC OLE (MFCOxxD.DLL) AfxOleInitModule
MFC Database (MFCDxxD.DLL) AfxDbInitModule
MFC Sockets (MFCNxxD.DLL) AfxNetInitModule

What do you want to do?

What do you want to know more about?