解决win32dll 使用MFC报 dllmain.obj 已定义

// 在WIN32DLL 中 使用MFC 会报错误   error LNK2005: _DllMain@12 已经在 dllmain.obj 中定义    nafxcw.lib    RadiumCarved

//是因为 把windows.h换成了afxwin.h后,有一个问题,afxwin.h中定义了一个Dllmain,而代码中又定义了一个Dllmain,所以链接时报错,Dllmain有重定义。

//新建一个.cpp文件  添加如下内容

//修改StdAfx.h文件:在#include <windows.h>前面加上#include <afx.h> ,加在后面就不行。并且这两个都要在stdafx.h的前面

#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

原文地址:https://www.cnblogs.com/nameliu/p/3499595.html