I use ATL / MFC string conversion macros. For example, if you have an ASCII string called myUTF8Str containing UTF8 characters:
::MessageBox(hWnd, CA2T(myUTF8Str, CP_UTF8), _T("Caption"), MB_OK);
Alternatively, you can create an instance of a string, for example:
CA2T myConvertedString(myUTF8Str, CP_UTF8); ... TRACE(_T("Converted: %s\n"), myUTF8Str.m_psz);
Notice the m_psz element, which allows read-only access to the raw string pointer.
You can also code using CT2A , for example:
CT2A myEncodedString("Some UTF8", CP_UTF8);
If you are not using TEXT macros, use CA2W, CW2A, etc.
Rob
source share