我有以下代码
void Test()
{
BSTR aBstr = ::SysAllocString(L"blah");
PrintBSTR(aBstr);
::SysFreeString(aBstr);
}
void PrintBSTR(BSTR _aBstr)
{
PrintWstring(_aBstr);
}
void PrintWstring(std::wstring _aWstring)
{
std::wcout << _aWstring << std::endl
}
它适用于Debug,但在Release中出现内存损坏。实际上,当我进入
PrintWstring
时,会得到一个错误的指针,并且_aWstring
包含垃圾。我猜SysAllocString
与文字不能很好地相处。任何想法? 最佳答案
将文字传递给SysAllocString
并没有错。
关于c++ - 将SysAllocString与文字一起使用是否有任何问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6841070/