dll中使用MFC对话框

如果自己添加DllMain函数,

VS报错 error LNK2005: _DllMain@12 已经在 MSVCRTD.lib(dllmain.obj) 中定义

InitInstance即是入口函数


When compiling regularDLLs that statically link to MFC, the symbols "_USR DLL" and"_WINDLL" must be defined. Your DLL code must also be compile dwith the following compiler switches:
When compiling regular DLLs that dynamicallylink to MFC, you must define t he above symbols and use the above compilerswitches. Additionally, the sy mbol "_AFXDLL" must be definedand your DLL code must be compiled with:
•/D_AFXDLL     specifies that you are building a regular DLL that dynamicall y links to MFC
The interfaces (APIs) between the application and the DLL must beexplicitlyexported. It is recommended that you define your interfaces to be lowbandw idth, sticking to C interfaces where possible. More direct C interfaces areeasi er to maintain than more complex C++ classes.
Place your APIs in aseparate header that can be included by both C and C++files (that way you won'tlimit your DLL customers to C++ programmers). Se e the header ScreenCap.h in theMFC Advanced Concepts sample DLLScreen Cap for an example. To export yourfunctions, enter them in theEXPORTSs ection of your moduledefinition file (.DEF) or include__declspec(dllexpor t)on yourfunction definitions. Use__declspec(dllimport)to import thesefunctions into the client executable.
You must add theAFX_MANAGE_STATEmacro at the beginning of all the e xportedfunctions in regular DLLs that dynamically link to MFC to set the curr ent modulestate to the one for the DLL. This is done by adding the followingline of codeto the beginning of functions exported from the DLL:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
WinMain->DllMain
The MFC library defines the standard Win32DllMain entry point that initializ es your CWinApp derived object as in a normal MFC application. Placeall DLL-specific initialization in the InitInstance member function as in a normal MFC application.

你可能感兴趣的:(C++)