views:

20

answers:

2

I have a certain library (IBM's WebSphere MQ) which I'm using, with an API that is suppose to return a remote servers character set.

After some debugging, it seems as though the return value of this function call returns the active code page of my machine. I saw this by looking at the return value of the function call and the result of running chcp in a command line - both returned 862. When I changed the language in the Control Panel->Regional and Language Options->Advanced tab to something else, both values changed again, which verified my suspicion.

My question is, what is the value that chcp returns? What Win32 API gets/sets it? How does it relate to locales? (trying to change the global locale in a C++ application using std::locale::global had no impact on it apparently).

+1  A: 

CHCP returns the OEM codepage (OEMCP). The API is Get/SetConsoleCP.

You can set the C++ locale to ".OCP" to match this locale.

MSalters
A: 

Locales mostly identifies languages, and given that historically there are not so many codepages (many languages' alphabet differ not so greatly from 26-Latin), several languages can be "mapped" to the same codepage. As I remember, there is no direct converstion function, but I made it with statistical approach:

  • For any given locale I collected this languages words I can obtain from the system (LOCALE_SMONTHNAME1..LOCALE_SMONTHNAME12, LOCALE_SNATIVELANGNAME etc) in Unicode

  • I called WideCharToMultiByte function for every string trying to convert them to this codepage one-byte encoding WideCharToMultiByte(CodePage, CP_ACP or WC_NO_BEST_FIT_CHARS, ..., @DefChar, @DefUsed);

    If DefUsed was set during the process, that it basically meant that this languages is not compatible with this codepage.

Maksee