今天写了一个DLL,DLL中用到的一个类里用到的MSXML的COM组件,所以在DLL中要包含afx.h头文件,也就不可避免的要用到MFC的类库了,但在编译时出现了错误:mfcs42d.lib(dllmodul.obj) : error LNK2005:_DllMain@12 already defined in NetDriverConfig.obj,

http://topic.csdn.net/t/20010911/10/281452.html 处的贴子里找到了以下回答,试了一个原来是文件里定义的对象与mfcs42d.lib有冲突,加了命名空间后问题解决。还不知道DLL能不能使用,明天试一下再说了!

Linker   Tools   Error   LNK2005   
  symbol   already   defined   in   object   
    
  The   given   symbol,   displayed   in   its   decorated   form,   was   multiply   defined.   
    
  Tips   
    
  One   of   the   following   may   be   a   cause:     
    
  The   most   common   cause   of   this   error   is   accidentally   linking   with   both   the   single-threaded   and   multithreaded   libraries.   Ensure   that   the   application   project   file   includes   only   the   appropriate   libraries   and   that   any   third-party   libraries   have   appropriately   created   single-threaded   or   multithreaded   versions.   
    
    
  The   given   symbol   was   a   packaged   function   (created   by   compiling   with   /Gy)   and   was   included   in   more   than   one   file   but   was   changed   between   compilations.   Recompile   all   files   that   include   the   symbol.   
    
  The   given   symbol   was   defined   differently   in   two   member   objects   in   different   libraries,   and   both   member   objects   were   used.   
    
  An   absolute   was   defined   twice,   with   a   different   value   in   each   definition.     
    
  Linker   Tools   Error   LNK1169   
  one   or   more   multiply   defined   symbols   found   
    
  The   build   failed   due   to   multiple   definitions   of   one   or   more   symbols.   This   error   is   preceded   by   error   LNK2005.   
    
  The   /FORCE   or   /FORCE:MULTIPLE   option   overrides   this   error.

-------------------------------------------------------------------------------------------------------------------------------------------------

今天又看了下发,发现在WIN32 DLL中使用MFC类库是会存在问题,原因是在MFC/src/DLLModul.cpp 文件中已经声明了DLLMain()函数,所以就不能在项目文件中再声明 DllMain(),否则就会出现如上所示的链接错误。所以在WIN32 DLL中使用MFC类库的话可以不声明DLLMain()函数,如果有操作要放在DLL加载时初始化的话就从CWinApp派生一个类,在项目文件里声明这个对象,在这个CWinApp类的InitInstance()成员函数中做初始化工作

在WIN32 DLL中使用MFC库遇到的问题的更多相关文章

  1. WIN32 DLL中使用MFC

    最近用WIN32 DLL,为了方便要用到MFC的一些库,又不想转工程,就网上找了很多方法,发现没有详细的介绍,有的也行不通,现在成功在WIN32 DLL中使用了MFC,记录一下以防以后用到忘记 一.修 ...

  2. 在WIN32 DLL中使用MFC

    最近用WIN32 DLL,为了方便要用到MFC的一些库,又不想转工程,就网上找了很多方法,发现没有详细的介绍,有的也行不通,现在成功在WIN32 DLL中使用了MFC,记录一下以防以后用到忘记 一.修 ...

  3. 在共享DLL中使用MFC 和在静态库中使用MFC的区别

    使用VS2008,在项目属性中有一项MFC的使用,有三种设置: 1.使用标准Windows库 2.在共享DLL中使用MFC 3.在静态库中使用MFC          第一种顾名思义.        ...

  4. c++MFC工程修改在共享DLL中使用MFC为使用标准Windows库的解决办法

    由于创建MFC工程时,默认是在共享DLL中使用MFC,如果将此选项改成使用标准Windows库,会报如下错误 c:\program files\microsoft visual studio 9.0\ ...

  5. MFC的使用——在共享DLL中使用MFC、在静态库中使用MFC(转)

    原文转自 https://blog.csdn.net/albertsh/article/details/52838419 1.使用标准Windows库 使用WINDOWS SDK API库,不使用MF ...

  6. 在共享DLL中使用MFC

    使用VS2008,在项目属性中有一项MFC的使用,有三种设置: 1.使用标准Windows库 2.在共享DLL中使用MFC 3.在静态库中使用MFC          第一种顾名思义.        ...

  7. win32 Dll 中添加afx.h 出现如下错误 error LNK2005: _DllMain@12 already defined

    win32 Dll 中添加afx.h 出现如下错误 nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in ...

  8. 非MFC工程中使用MFC库

    目录(?)[-] 需求说明 常见问题 问题分析 参考解决方法 我的解决方案 Stdafxh的原理   需求说明 C++工程的类型有很多,从VS(或VC)可以看到常见的有:Win32 Console A ...

  9. 在WIn32程序中使用MFC的CInternetSession运行异常,主要是因为获取目前应用程序名出错的解决办法

    转载:http://group.gimoo.net/review/22564 头文件#include <afxinet.h"> 在非MFC工程中使用CInternetSessio ...

随机推荐

  1. TSQL基础(三)

    字符处理函数 sql中常见的字符类型有: char(n) --长度固定 不可变 非Unicode 字符数据 n 必须是一个介于 1 和 8,000 之间的数值 nchar(n) --长度固定 不可变 ...

  2. SQL server 2008 安装问题解决

    安装sqlserver2008 出现的一些问题解决方法 1,安装sqlserver的时候出现如下图所示,解决办法是:开始→运行→输入“regedit”→找到“HKEY_LOCAL_MACHINE\SY ...

  3. WebResponse 取出全国省市区的邮编

    WebResponse用法(根据省市区地址查询其邮编): class Program { static string url { get; set; } static void Main(string ...

  4. Paying for upgrades, by Bob Arnson

    Following content is reprinted from here, please go to the original website for more information. Au ...

  5. (四)Qt之右键菜单

    1.右键菜单创建和显示 作为一种交互性强.使用方便的右键菜单在程序中是非常常用的,在Qt中可以轻松的实现. QMenu menu; //添加菜单项,指定图标.名称.响应函数 menu.addActio ...

  6. mysql 运行sql脚本文件

    #只运行,不导出 mysql> source /home/user/to_run.sql; #导出 $ mysql -h host -u user -ppassword database < ...

  7. vm NAT方式linux上不了网 解决方法

    环境: vm版本:vm 11.0.0 系统:本机win7 虚拟机:centos 5.5   问题,当vm设置虚拟机上网方式为NAT方式时,两台虚拟centos能互相ping通.主机能拼通虚拟机,但虚拟 ...

  8. 发送邮件(遵循smtp协议即简单的邮件发送协议)

    HandleSendEmail.aspx逻辑 protected void Page_Load(object sender,EventArgs e) { foreach(var item in Req ...

  9. soinn

    Growing Cell Structures A Self-Organizing Network for Unsupervised and Supervised Learning Here, and ...

  10. TDBAdvGrid 只读状态下复制功能

    DataSource1.AutoEdit := false;