开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜