If you want to pass this as a string to JavaScript you really need to use CAPICOM_ENCODE_BASE64
- otherwise the values in this buffer could be anything, including values outside the character space. Some code obviously checks for this, causing your exception.
If you only need to use this internally in your plugin, don't use strings but e.g. a std::vector<WCHAR>
or just use the BSTR
.
Side note: it won't matter in this case, but BSTR
s are length prefixed and both BSTR
s and std::wstring
s can contain embedded 0
s - so to be correct you really would have to return std::wstring(bstr.GetBSTR(), bstr.length())
.