While working with COM in C++ the strings are usually of BSTR
data type. Someone can use BSTR
wrapper like CComBSTR
or MS\'s CSt
BSTR
to std::wstring
:
// given BSTR bs
assert(bs != nullptr);
std::wstring ws(bs, SysStringLen(bs));
std::wstring
to BSTR
:
// given std::wstring ws
assert(!ws.empty());
BSTR bs = SysAllocStringLen(ws.data(), ws.size());
Doc refs: