佚名通过本文主要向大家介绍了bstr,bstr t,bstr是什么类型,bstr转cstring,vt bstr等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: BSTR引发crash,程序自动关闭。
描述:
c++ dll中有以下一函数:
BSTR GetStr()
{
char str[100];
.......//str赋值
_bstr_t b_s;
BSTR bstr=NULL;
b_s=str;
bstr=b_s.copy();
return bstr;//调试发现程序到运行到此处时仍然正常,bstr已经正常赋值如"A1"
}
C#调用:
string Name = new string(' ', 1);
Name = rs.GetStr();//rs定义省略。程序在此处直接退出关闭.发生crash
//错误信息
Problem signature:
Problem Event Name: APPCRASH
Application Name: my.exe
Application Version: 2.12.5.0
Application Timestamp: 4fbb0c38
Fault Module Name: StackHash_6b65
解决方案1:
描述:
本帖最后由 hbvanguard 于 2012-06-13 12:50:00 编辑
C#里面调用C++写的dllc++ dll中有以下一函数:
BSTR GetStr()
{
char str[100];
.......//str赋值
_bstr_t b_s;
BSTR bstr=NULL;
b_s=str;
bstr=b_s.copy();
return bstr;//调试发现程序到运行到此处时仍然正常,bstr已经正常赋值如"A1"
}
C#调用:
string Name = new string(' ', 1);
Name = rs.GetStr();//rs定义省略。程序在此处直接退出关闭.发生crash
//错误信息
Problem signature:
Problem Event Name: APPCRASH
Application Name: my.exe
Application Version: 2.12.5.0
Application Timestamp: 4fbb0c38
Fault Module Name: StackHash_6b65
解决方案1:
官方例子
STDMETHODIMP CAlertMsg::get_ConnectionStr(BSTR *pVal){ // m_bsConStr is _bstr_t
*pVal = m_bsConStr.copy();
}
BSTR GetStr()
{
char str[100];
.......//str赋值
_bstr_t b_s;
BSTR bstr=NULL;
b_s=str;
bstr=b_s.Detach();
return bstr;
}