问题描述
我正在尝试将Winform项目链接到本机lib.
winform项目是使用/clr编译的(不是clr ure)并链接到/MDd.
本机lib编译为无clr支持,并且还编译为/MDd
两个项目非常简单.
winform只是Visual Studio 2005创建的默认项目.
lib项目是一个标头和一个cpp文件.
标头很简单:
class CTestClass { CTestClass();
〜CTestClass();
int test;
};
cpp文件只是
>
#include< string>
const std: tring testString ="test";
CTestClass :: CTestClass(){}
CTestClass ::〜CTestClass(){}
就是这样.
但是当我运行它时,我遇到访问冲突.
这是调用堆栈:
> msvcr80d.dll!_msize_dbg(void * pUserData = 0x721fb816,int nBlockUse = 2)行1473 + 0x30字节C ++
msvcr80d.dll!_dllonexit_nolock(int(void)* func = 0x725f8f56,void(void)* * * 0x0012ee20,void(void)* * * pend = 0x0012ee18)行295 + 0xd字节C
msvcr80d.dll!__ dllonexit(int(void)* func = 0x725f8f56,void(void)* * * pbegin = 0x0012ee20,void( void)* * * pend = 0x0012ee18)行273 + 0x11字节C
CLRTest.exe!_onexit(int(void)* func = 0x00403740)行110 + 0x1b字节C
CLR
CLRTest.exe!atexit(void void)* func = 0x00403740)第127行+ 0x9字节C
CLRTest.exe!'kElementName_StockTextures的动态初始化程序''()第5行+ 0x41字节C ++
[托管到本机转换]
CLRTest. exe!_initterm(void ** pfbegin = 0x004040D8,void pfend =)行130 C ++
CLRTest.exe!< CrtImplementationDetails> :: LanguageSupport :: InitializeNative()行534> C ++ mp< CLRTest! ; ::兰瓜eSupport :: _ Initialize()第680行C ++
CLRTest.exe!< CrtImplementationDetails> ::: LanguageSupport :: Initialize()第824行+ 0x9字节C ++
CLRTest.exe !? )872行C ++
为什么在msvcr80d中呢?
我以为混合程序集应该链接到Msvcmrt?
无论如何,我只想试图获取Winform以使用本机lib.我在做什么错?
谢谢.
这是在Win XP SP2上.
Visual Studio 2005 .Net
.nett Framework 2.0
我刚运行Windows Update,所以所有内容都已修补.
BTW:
如果我运行正常
其他类型似乎没有问题..字符串确实有问题.
I am trying to link a Winform project to a native lib.
The winform project is compiled with /clr (not clrure) and linking to /MDd.
The native lib is compiled no clr support and also /MDd
Both projects are very simple.
The winform is simply the default project created by visual studio 2005.
The lib project is one header and one cpp file.
The header is simply:
class CTestClass {
public:
CTestClass();
~CTestClass();
int test;
};
The cpp file is simply
#include <string>
const std:tring testString = "test";
CTestClass ::CTestClass (){}
CTestClass ::~CTestClass(){}
And that is it.
The whole project compiles no problem.
But when I run it I get an access violation.
Here is the call stack:
> msvcr80d.dll!_msize_dbg(void * pUserData=0x721fb816, int nBlockUse=2) Line 1473 + 0x30 bytes C++
msvcr80d.dll!_dllonexit_nolock(int (void)* func=0x725f8f56, void (void)* * * pbegin=0x0012ee20, void (void)* * * pend=0x0012ee18) Line 295 + 0xd bytes C
msvcr80d.dll!__dllonexit(int (void)* func=0x725f8f56, void (void)* * * pbegin=0x0012ee20, void (void)* * * pend=0x0012ee18) Line 273 + 0x11 bytes C
CLRTest.exe!_onexit(int (void)* func=0x00403740) Line 110 + 0x1b bytes C
CLRTest.exe!atexit(void (void)* func=0x00403740) Line 127 + 0x9 bytes C
CLRTest.exe!`dynamic initializer for 'kElementName_StockTextures''() Line 5 + 0x41 bytes C++
[Managed to Native Transition]
CLRTest.exe!_initterm(void** pfbegin = 0x004040D8, void pfend = ) Line 130 C++
CLRTest.exe!<CrtImplementationDetails>::LanguageSupport::InitializeNative() Line 534 C++
CLRTest.exe!<CrtImplementationDetails>::LanguageSupport::_Initialize() Line 680 C++
CLRTest.exe!<CrtImplementationDetails>::LanguageSupport::Initialize() Line 824 + 0x9 bytes C++
CLRTest.exe!?.cctor@@$$FYMXXZ() Line 872 C++
Why is it in msvcr80d???
I thought the mixed assemblies where supposed to link to Msvcmrt?
Anyway, I wam just trying to get a Winform to use a native lib. What am I doing wrong?
Thanks.
This is on Win XP SP2.
Visual Studio 2005 .Net
.Nett Framework 2.0
I just ran windows update so everything is patched.
BTW:
It runs fine if I comment out the string.
Other types seem to not have a problem.. string does.
推荐答案
是的,当您使用/clr和/MDd选项,生成的可执行文件依赖于msvcm80d.dll.但是msvcm80d.dll不是孤立的dll,它具有对msvcr80d.dll的依赖性,它的某些功能称为msvcr80d.dll的导出功能.您可以使用工具 (depends.exe).
要查找访问冲突的原因,您能否在混合程序集中发布如何使用本机库?
谢谢! 字体>
这篇关于混合装配. Winform链接到本机lib.字符串访问冲突.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!