views:

508

answers:

2

I am building an MFC C++ application with "Use Unicode Character Set" selected in Visual Studio. I have UNICODE defined, my CStrings are 16-bit, I handle filenames with Japanese characters in them, etc. But, when I put Unicode strings containing Japanese characters in a CComboBox (using AddString), they show up as ?????.

I'm running Windows XP Professional x64 (in English). If I use Windows Control Panel Regional and Language Options, Advanced Tab, and set the Language for non-Unicode programs to Japanese, my combo box looks right.

So, I want my combo box to look right, and I want to understand why the "Language for non-Unicode programs" setting is changing the behavior of my Unicode program. Is there something else I should do to tell Windows my application is a Unicode application?

Thanks for any help!

+6  A: 

Windows knows the difference between Unicode and non-Unicode programs by the functions they call. Most Windows API functions will come in two variants, one ending in A for non-Unicode and one ending in W for Unicode. The include files that define these functions will use the compiler settings to pick one or the other for you automatically.

The characters might not be coming out properly because you've selected a font that doesn't include them to be your default UI font.

Mark Ransom
Thanks, Mark. I changed the "Language for non-Unicode programs" back to English, but my CComboBox still looks right!I'm thinking the switch installed a larger system font which got left behind when I went back to English. Perhaps that's what you meant by "default UI font"? I can't find any other references to a "default UI font" here or on MSDN.
Mark Gilbert
djeidot
A: 

Where do you get the strings from? If they are hard-coded in your C sources, then at the time you call AddString they are (most likely) already damaged.

Nothing prevents one from taking some Unicode string, "squeeze" it in a std::string, for instance, and damage it. Even if the applications is compiled as Unicode.

Mihai Nita
They are 16-bit wchar_t strings, and they look right in the debugger. I can do anything with them except add them to a combo box.
Mark Gilbert