Initializing Regular DLLs
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.
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?
- The C run-time library behavior and _DllMainCRTStartup
- Using Database, OLE, and Sockets Extension DLLs in Regular DLLs
- Processes and threads (Platform SDK)
- Thread local storage wrappers (MFC Technical Note 58)