I have a _bstr_t
string which contains Japanese text. I want to convert this string to a UTF-8 string which is defined as a char *
.
Can I convert the _bstr_t
string to char *
(UTF-8) string without losing the Japanese characters?
I have a _bstr_t
string which contains Japanese text. I want to convert this string to a UTF-8 string which is defined as a char *
.
Can I convert the _bstr_t
string to char *
(UTF-8) string without losing the Japanese characters?
Use WideCharToMultiByte() – pass CP_UTF8 as the first parameter.
Beware that BSTR can be a null pointer and that corresponds to an empty string – treat this as a special case.
Very handy MSDN reference for this sort of thing: http://msdn.microsoft.com/en-us/library/ms235631(VS.80).aspx
I think you need to go to wchar_t* since char* will lose the Unicode stuff, although I'm not sure.
Here is some code that should do the conversion.