问题描述
嘿,
我希望外面有人比我聪明:).
从VS2003 MFC项目访问以VS2005编写的静态库时,我遇到了这个奇怪的问题.代码使用本机C ++.
我在VS2003项目中使用静态绑定.
我可以很方便地访问库并执行方法,但是当我在VS2003中通过ref(或std :: vector)传递std :: string时,似乎VS2005中的内存位置偏移了4个字节,导致<删除的ptr =">和崩溃.
我将方法称为"Foo(std :: string& arg_szError);"
在VS2003中,我的字符串的地址为0x0013F4C0,但是当我在VS2005中调试Foo时,我的字符串的地址突然变为0x0013F4C4,其结果为已知.
有趣的是,它实际上工作了一段时间,但是我不得不将解决方案中的一些项目移到不同的目录,从那时起,我就遇到了这个非常烦人的问题.
我认为有些事情(很可能是我:()弄乱了代码生成和/或链接选项.
我认为这是一些有用的选项.
VS2003:
常规选项:应用程序(exe),在共享dll中使用MFC,而不使用ATL,MBCS
C/C ++:多线程调试DLL,默认结构成员对齐,__ cdelc
链接器:不忽略默认库
VS2005:
常规选项:静态库,使用标准Windows库,动态链接到ATL,MBCS
C/C ++:多线程调试,默认结构成员对齐,__ cdelc
使用2种不同IDE的主要原因是,我正在使用模板库来执行一些矩阵计算,这些计算仅适用于VS2005或更高版本,而我的主应用程序附带了为VS2003编写的第三方库(我尝试升级,但由于库中有一些MFC引用而失败,这些引用当然不属于该库.)
预先感谢您尝试帮助我解决这个问题!
Hey there,
I hope someone out there is alot smarter than I am :) .
I have this strange problem when accessing a static library written in VS2005 from a VS2003 MFC-project. Code is in native C++.
I use static binding in my VS2003-project.
I have no trouble accessing the lib, and executing the methods, but when I pass an std::string by ref (or an std::vector) in VS2003, it seems that the memory-location in VS2005 is shifted by 4 bytes, resulting in a <removed ptr=""> and a crash.
I call a method "Foo(std::string& arg_szError);"
In VS2003, the address of my string is 0x0013F4C0, but when I debug Foo in VS2005, the address of my string suddenly became 0x0013F4C4, with the known result.
The funny thing is that it actually worked for a little while, but I had to move some projects in my solution to different directories and since then, I get this very annoying problem.
I think something (most probably me :( ) messed up the code-generation and/or linking options.
Here are some options which, I think, could be useful.
VS2003:
General options: application (exe), use MFC in shared dll, not using ATL, MBCS
C/C++: Multi-threaded Debug DLL, default struct member alignment, __cdelc
Linker: not ignoring default libraries
VS2005:
General options: static library, use standard windows libraries, dynamic link to ATL, MBCS
C/C++: Multi-threaded Debug, default struct member alignment, __cdelc
The main reason for using 2 different IDE''s is that I''m using a template-library to do some matrix-calculations which only ships for VS2005 or higher, and my main-app comes with 3rd party libs written for VS2003 (I tried to upgrade, but it failed due to some MFC-references in the libs, which of course don''t belong there).
Thanks in advance for trying to help me out of this!
推荐答案
这篇关于在VS2003中使用VS2005-lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!