win .net 问题汇总

来源:互联网 发布:ubuntu 串口调试工具 编辑:程序博客网 时间:2024/06/01 08:05

今天遇到了一个问题,在csdn上寻找解决方案,找了许久没找到。结果msdn上立马找到。 而且作者的分析令人叹为观止。做技术做到见微知著、所有问题都迎刃而解的地步,是在是个令人向往的境界。 


error  link 2005    

Error 24 error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj) uafxcwd.libError 22 error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) uafxcwd.libError 23 error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj) uafxcwd.libError 21 error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) uafxcwd.lib
solution  1  :    Force Linker to Link Libraries in Correct Order

When you use the MFC libraries, you must make sure that they are linked before the CRT library is linked. You can do this by making sure that every file in your project includes Msdev\Mfc\Include\Afx.h first, either directly (#include ) or indirectly (#include ). The Afx.h include file forces the correct order of the libraries, by using the directive:

#pragma comment (lib,"<libname>")

CRT 是 C运行时库,上面的意思是在mfc程序中使用到crt函数时,应该让mfc先于crt链接。 这个一般情况下IDE能帮忙解决,可是有时程序配置不当,确实会出现这个问题。 解决方法很简单,包含afx.h即可。(当然问题是有针对性的)


solution 2: Locate and Correct the Problem Module

问题的发生是因为crt提供了new delete dllmain 的弱链接,而mfc中也有它们的定义,避免使用它们既可。当然这不是好办法。 所以应该在一开始就把程序配置好。

http://social.msdn.microsoft.com/Forums/en-US/ceb90f33-b348-42a7-9e23-a533ba0c7da4/uafxcwdlibdllmodulobj-error-lnk2005-dllmain12-already-defined-in-mytestdllobj

http://stackoverflow.com/questions/3586195/visual-studio-linking-errors-order-in-which-mfc-crt-included

翻译自msdn ---   内核对象命名冲突 :    在处理进程和线程的同步问题时, 对于同步函数CreateX(mutex, semaphare, event, timer等),如果是非第一次(即,已经使用过CreateX )使用且生成同名的object, 则判断其类型是否相同,如果类型相同,则相当于OpenX函数,但是会生成错误码  ERROR_ALREADY_EXISTS; 否则,函数失败, 错误码 ERROR_INVALID_HANDLE。 。 如,对于名字为mm的mutex, 第二次调用createmutex ,相当于openmutex;  但是如果调用createevent生成名字为mm的事件, 则函数失败--  因为所有的内核对象共享同一个命名空间。


翻译自msdn ---   应该知道, 所有能够在注册表中定位到某一项的函数都是不安全的,因为它们都有可能修改注册表。而 如RegQueryValueEx 函数,没有对NULL-TERMINATED字符的判断(也是不安全的), 所有这些需要调用者充分考虑到;     CRegKey封装了读写(本机)注册表的函数,唯有关闭注册表( CRegKey::Close ) 时, 写入的内容才会被保存,但是这个过程可能会花费几秒钟。RegFlushKey 函数可以不用关闭注册表就能把注册表的改变内容写入到硬盘,但是应该慎用,因为写注册表这个过程毕竟是很耗时的。  



0 0
原创粉丝点击