My VC++ (VS2008) project uses Multi-byte Character set.
I've the following code to convert a date string to COleDateTime
_bstr_t bstr_tDate = bstrDate; //bstrDate is populated by a COM function
const CString szStartDateTime = bstr_tDate.operator const char *();
bool bParseOK = oleDateTime.ParseDateTime(szStartDateTime);
This code works well in all regional settings, but fails in Arabic regional settings, where the input date is this format: 21/05/2012 11:50:31م
After conversion, the CString contains junk characters and parsing fails: 01/05/2012 11:50:28ã
Is there a BSTR to CString conversion that works in Arabic settings?
BSTR is string consisting of UTF-16-encoded Unicode codepoints (wide "chars", 16-bit):
which means that special characters like 'م' are represented by single
WCHAR
. In multi-byte string (C-stylechar*
orstd::string
) are these special characters represented by more characters (therefore it's called "multi-byte").The reason why your
CString
contains junk characters is because you retrievechar*
directly from_bstr_t
. You need to convert this wide-char string to multi-byte string first. There are more ways how to do that, one of them is to use WideCharToMultiByte function.This question will also help you: How do you properly use WideCharToMultiByte