vs2005中写了个功能函数:
int fucn(vector<string> &out)
{
out.push_back("test");
return 1;
}
VC6可调用这个DLL
_declspec int fucn(vector<string> &out);
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
vector<string> strList;
string tem;
if (fucn(strList))
{
for (size_t i=0;i<strList.size();i++)
{
tem=strList[i];
}
}
return;
}
在程序运行到tem=strList[i]时弹出个错误:
unhandled exception in testdlg.exe(MSVCP60D.DLL):0XC0000005:Access Violation
不解是怎么回事?另外两个编辑器都用的MBCS
int fucn(vector<string> &out)
{
out.push_back("test");
return 1;
}
VC6可调用这个DLL
_declspec int fucn(vector<string> &out);
void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
vector<string> strList;
string tem;
if (fucn(strList))
{
for (size_t i=0;i<strList.size();i++)
{
tem=strList[i];
}
}
return;
}
在程序运行到tem=strList[i]时弹出个错误:
unhandled exception in testdlg.exe(MSVCP60D.DLL):0XC0000005:Access Violation
不解是怎么回事?另外两个编辑器都用的MBCS
在return;的时候,会报错 __CLR_OR_THIS_CALL basic_string(_Has_debug_it _Hdi = _Has_debug_it(false))
: _Mybase()
{ // construct empty string
if (!_Hdi._Value)
{
this->_Myfirstiter = _IGNORE_MYITERLIST;
}
_Tidy();
} #endif
这样的代码,即使使用相同的编译器
在XP下能正常运行
VISTA下,程序会挂掉的
外部程序在栈上分配的vector
却在dll内插入了值
最终释放的时候是在外部程序
结果是dll内分配的内存,在外部程序释放
如果非要使用vector,函数接口需传入vector数组的指针
同时dll还需要提供释放函数
使用完后释放掉