Monday 15 August 2011

c++ - Default encoding for variant bstr to std::string conversion -


I have a version BST pulled from the MSX dom, so it is in UTF-16. I'm trying to figure out what the default encoding is with this conversion:

  VARIANT vtNodeValue; PNode-> Get_nodeValue (& amp; vtNodeValue); String strValue = (char *) _ bstr_t (vtNodeValue);  

By testing, I believe the default encoding is either Windows 1252 or ASCI, but I'm not sure.

BTW, this is part of code I

Thanks!

operator four * method call _com_util :: ConvertBSTRToString () . Very disappointed, but I think it uses the existing locale setting to perform the conversion.

Update:

Internal, _com_util :: ConvertBSTRToString () call WideCharToMultiByte , for all code pages and default character parameters Zero is passing. This is similar to passing CP_ACP , which means that the current ANSI code-page setting of the system (not the current thread setting) is to be used.

If you want to avoid losing data, you should probably call directly Wide Multibyte and use CP_UTF8 . You can still consider the string as a redundant single-byte string and you can use std :: string , you can not consider the bytes as characters.


No comments:

Post a Comment