开发者

Are there any problems using SysAllocString with literals?

开发者 https://www.devze.com 2023-03-23 17:55 出处:网络
I have the fo开发者_运维技巧llowing code void Test() { BSTR aBstr = ::SysAllocString(L\"blah\"); PrintBSTR(aBstr);

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

精彩评论

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