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

StackOverflow https://stackoverflow.com/questions/7736618

Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

Yes. I saved RC file using VS 2010 'Advanced Save Options'->'Unicode - Codepage 1200', I tried using 1200 codepage '1200' in WideCharToMultiByte but still no go.

Well that's only doing partly the trick actually you need to specify the encoding for the data in the .rc file like this:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN)
#ifdef _WIN32
LANGUAGE LANG_JAPANESE,SUBLANG_JAPANESE_JAPAN
#pragma code_page(932)
#endif

STRINGTABLE
BEGIN
   STR_ID "<Japanese text goes here>"
END

#endif
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top