项目原是个Win32的DLL,现在希望在项目中使用CString
把项目MFC使用改为了"在静态库中使用 MFC"
把#include "Windows.h"替换成了#include "afxwin.h"
在stdafx.h中添加了
#ifndef WINVER                  // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0500          // Win2k
#endif#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0500    // Win2k
#endif
编译的时候提示:1>nafxcw.lib(dllmodul.obj) : error LNK2005: _DllMain@12 已经在 dllmain.obj 中定义
接下来还需要再该什么啊?

解决方案 »

  1.   

    在dll或者lib的工程中,由于afx.h默认带了一个DllMain,致使要使用CString类需要几个步骤。1、首先和控制台程序一样,如果编译环境设置了采用单线程库, 要改成多线程库,这个可以从工程属性里进行修改,可以直接把它复制到工程里使用:
       #ifdef _DEBUG
       #pragma comment(lib, "libcmtd.lib")
       #else
       #pragma comment(lib, "libcmt.lib")
       #endif      
    2、工程目录下创建一个DLLMODUL.CPP文件,并且把它加入到当前工程中。
    3、打开DLLMODUL.CPP文件,编辑这个文件为这样:  
      #include "stdafx.h"
       #ifdef _DEBUG
       #undef THIS_FILE
       static char THIS_FILE[] = __FILE__;
       #endif
       
       #define new DEBUG_NEW
       
       /////////////////////////////////////////////////////////////////////////////
       // global data
       
       // The following symbol used to force inclusion of this module for _USRDLL
       #ifdef _X86_
       extern "C" { int _afxForceUSRDLL; }
       #else
       extern "C" { int __afxForceUSRDLL; }
       #endif  
     4、打开stdafx.h,把afx.h包含在windows.h前面。现在可以正常的使用CString了。