Are there any problems using SysAllocString with literals?
I have the fo开发者_运维技巧llowing code
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
}
It works well for Debug, but I get memory corruptions in Release. Actually, I get a bad pointer when I'm into PrintWstring
, and _aWstring
contains rubbish. I'm guessing SysAllocString
doesn't get on very well with literals. Any idea?
There is nothing wrong with passing a literal to SysAllocString
.
精彩评论