ATL中使用MFC的链接错误

CodeProject-Jerry 2006-05-23 03:11:30
用VC8.0向导 建了一个 Vc/ATL的工程 做Visual Studio 2005 的 PlugIn

在stdafx.h添加了 #include <afx.h> 后, 出现链接错误:
mfcs80ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in AddIn.obj
Creating library Debug/CodeGenerator.lib and object Debug/CodeGenerator.exp
Debug/CodeGenerator.dll : fatal error LNK1169: one or more multiply defined symbols found

找到一篇文章:
http://www.codeproject.com/buglist/linkererrors.asp?df=100&forumid=15354&exp=0&select=526635#xx526635xx

此牛人说:
I'm going to bet that when you created your ATL DLL project, you had the "Attributed" flag checked in the project settings, and didn't check the "Include MFC support" option before you had visual studio create the project. The easiest way to get around this is to just make a new project, and select the right options:

Create a new project, and set the project type to: "Atl Project"

When the ATL project wizard appears, click the "Application Settings" link to the left.

Uncheck "Attributed", and check "Support MFC". Then click "Finish" to let visual studio build out your project.

You will then be able to use your MFC functions without the linker error. An attributed ATL dll defines DllMain, and so does the MFC library, so you are getting a collision there. By using the method, Visual Studio will build your interface class from MFC instead of ATL, and thus will not specify that ATL should provide a DLL main. You could also adjust your compiler settings to make this happen, but I think you will be happier to just remake the project and let VS do all the work.

Good luck!
Nick.


重建工程 这个方法对我是没用的 因为这个是特别的ATL 且向导里面也没有地方让我选“属性”


问题是 我在源码里面 找了很久 久是没找到 他说的“属性”

还有一个外国SB说要建立一个MFC的DLL 导出标准函数 在ATL里面调用
这种方法我不想用


请问如何 才能让我 MFC ATL在一个工程里面用


谢谢

...全文
279 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
SamdyCai 2006-10-10
  • 打赏
  • 举报
回复

I used VS2005 ATL template to create one project, then I want to using DLLMain(), and occur the same problem, and I resolved it with the following method:
//DO not use the following Macro in your exposed method for COM register/life-cycle manger such as: DllCanUnloadNow().

// AFX_MANAGE_STATE(AfxGetStaticModuleState());

hopefully it gives you helps.
CodeProject-Jerry 2006-05-24
  • 打赏
  • 举报
回复
ding
CodeProject-Jerry 2006-05-24
  • 打赏
  • 举报
回复
谢谢楼上 这种方法上 说 在 非MFC环境下 使用MFC的库

但是我这里好像不适用
我已经把工程改得同时 用 ATL MFC了

其它好像都正常 就是 资源句柄不正常

AfxGetResourceHandle() 一进去就断言
化外之民 2006-05-23
  • 打赏
  • 举报
回复
给你的项目添加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

修改StdAfx.h文件:在#include <windows.h>前面加上#include <afx.h> ,加在后面就不行。
wlwlxj 2006-05-23
  • 打赏
  • 举报
回复
建议你新建一个支持mfc的atl程序,比较一下不同之处,主要就是头文件还有入口函数的问题
CodeProject-Jerry 2006-05-23
  • 打赏
  • 举报
回复
// DLL 入口点
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
_AtlModule.SetResourceInstance(hInstance);
return _AtlModule.DllMain(dwReason, lpReserved);
}

找到这段 删除就可以了

问题是 资源句柄从哪里去找呢? 难道GetMoudleHandle?
CodeProject-Jerry 2006-05-23
  • 打赏
  • 举报
回复
fen分好像忘记调了 如果这个问题解决了 我再给分 :)

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧