c++windowsunicodemfcwidechar

Converting Japanese characters from wide characacter to multibyte using API WideChartoMultibyte gives '????'


In my MFC application I am reading Japanese characters from string table then converting it into multibyte using following code

WCHAR wBuf[1024];
int rc;

rc = LoadStringW(hInstance, iResourceID, wBuf, 1024);

WideCharToMultiByte(1252, WC_COMPOSITECHECK, wBuf, -1, buf, 1024, NULL, NULL);

But every Japanese character is converted into '????' I tried to change the codepage from 1252 to 1200 but no help.


Solution

  • Windows-1258 is the code page for Vietnamese text. Japanese cannot be expressed in the Vietnamese code page, so the output is mapped to question marks. The same goes for 1252, it's only for West European languages.

    In the case of 1200, that's not a real code page: according to MSDN, it's only available to managed applications (i.e. .NET).

    I'd strongly suggest just working with the Unicode directly, but if you absolutely must convert this to a multibyte character set, you'll need one that supports Japanese, in which case Shift-JIS, code page 932, is the usual code page.