debug版exe调release版dll库的一个问题
bo96 2005-03-23 06:26:40 先建一个dll,在里面建一个导出类CMyClass
添加函数
CString CMyClass::Get()
{
CString dllstr;
dllstr.Format("hello");
return dllstr;
}
再建一个exe,调用这个dll
测试函数如下
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CMyClass cls;
CString str;
str = cls.Get();
AfxMessageBox(str);
}
debug版exe调debug版dll库或release版exe调release版dll库结果都正常,不再讨论
用debug版exe调release版dll库时,点击button1,AfxMessageBox显示完结果后,exe程序会出异常.
debug assertion failed
file:dbgheap.c
line:1044
expression:_CrtIsValidHeapPointer(pUserData)
还有几个,不一一列出了.
但是如果将dll中的CString dllstr定义成CMyClass的类成员变量,而不在函数体中定义,就没有问题.
CMyClass::Get()函数返回的是变量值,应该会自动拷贝值,不是属于栈内存的问题.同样的写法在其它情况下也都正常.
请高手解释一下程序在这种情况下调用dll时,实际的机制是什么样的,为什么会出现这种情况.