Initializing Regular DLLs
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at 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
|Type of MFC support||Initialization function to call|
|MFC OLE (MFCOxxD.dll)||
|MFC Database (MFCDxxD.dll)||
|MFC Sockets (MFCNxxD.dll)||