Search code examples
c++bstr

Convert LPCOLESTR to BSTR?


Any ideas on how to make a BSTR out of an LPCOLESTR? Silly thing to get hung up on..


Solution

  • An LPCOLESTR is just a const wchar_t*, so you can use SysAllocString() to create a BSTR:

    LPCOLESTR olestr = ...;
    BSTR bstr = SysAllocString(olestr);
    

    Be sure to call SysFreeString() when you're done with your BSTR. See also the MSDN documentation on BSTRs