我的具体步骤如下:
1。首先通过MFC DLL向导生成模板
2。加入对话框资源及类声明
3。建立倒出文件:MyExport.h ,MyExport.cpp
   其中在MyExport.h中定义了一个函数:
   const char* AFX_EXT_API GetDlg()//用于打开对话框如果将MyExport.h ,MyExport.cpp从DLL工程中移去则编译通过,将MyExport.h ,MyExport.cpp加入工程则提示如下错误:
e:\dlltest\dlgext\atomdlg.h(157) : warning C4518: '__declspec(dllexport ) ' : storage-class or type specifier(s) unexpected here; ignored
e:\dlltest\dlgext\atomdlg.h(166) : warning C4518: '__declspec(dllexport ) ' : storage-class or type specifier(s) unexpected here; ignored
Generating Code...
Linking...
mfcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in DlgExt.obj
mfcs42d.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already defined in DlgExt.obj
mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in DlgExt.obj; second definition ignored
mfcs42d.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already defined in DlgExt.obj; second definition ignored
   Creating library Debug/DlgExt.lib and object Debug/DlgExt.exp
Debug/DlgExt.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
不知道待倒出的函数应该在何处声明,请各位高手帮忙。谢谢!

解决方案 »

  1.   

    def中书写导出函数。
    在.h中声明,前面加上 extern
      

  2.   

    在函数声明前面加上__declspect(__dllexport)
      

  3.   

    声明有问题:
    AFX_EXT_API const char * GetDlg(); // 或者
    const char AFX_EXT_API * GetDlg();
      

  4.   

    此外,看错误提示并不象是一个 MFC Extension 工程(似乎是 MFC Regular DLL us static MFC )?试试:
    Project Setting --> General --> Using MFC in shared DLL
    Project Setting --> C/C++ --> Preprocessor Definitions 中间的添加 _AFXDLL,_AFXEXT 并且修改你的 DllMain 代码如下:
    static AFX_EXTENSION_MODULE AfxModuleDLL = { NULL, NULL };extern "C" int APIENTRY
    DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    {
    UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH)
    {
    if (!AfxInitExtensionModule(AfxModuleDLL, hInstance))
    return 0; new CDynLinkLibrary(AfxModuleDLL);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    AfxTermExtensionModule(AfxModuleDLL);
    }
    return 1;   // ok
    }