Link to home
Start Free TrialLog in
Avatar of serg111
serg111

asked on

How to get current codepage?

How can I findout what codepage is currntly used by user?
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Avatar of serg111
serg111

ASKER

The GetThreadLocale() function returns the calling thread's current locale.

In my case it always return 1033 - is it language ID?

If I change Input language of edit control - this function still return 1033
I'd like to findout codepage number that are listed under
HKEY_CLASSES_ROOT\MIME\Database\Codepage\
Locale IDs (LCIDs) are not the same as codepages. 1033 is the decimal locale id for U.S. English.

Try _getmbcp() -- it returns an int which is the current multibyte codepage.
Avatar of serg111

ASKER

In which DLL is this function? I cant find it on my computer with WinXP :-(
It's in the C runtime libraries. You might need to include the header file mbctype.h.
Avatar of serg111

ASKER

I am using borland C and it doesn't have this function in mbctype.h
Do you know what library does contain this function?
Borland C -- which version exactly?
Avatar of serg111

ASKER

This is Version 5.02

ASKER CERTIFIED SOLUTION
Avatar of hupe
hupe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of serg111

ASKER

I've got 2 errors with this code :-(

undefined symbol: langLCID
undefined symbol: LOCALE_RETURN_NUMBER
The langLCID is the value get from e.g. GetUserDefaultLCID() or some other functions. The other
is define, defined somewhere is win32-includes (in my MS Visual.NET it's winnls.h, but only Win98
and later). See documentation for GetLocaleInfo().
Avatar of serg111

ASKER

OK, it works without LOCALE_RETURN_NUMBER too

but it always return langCP=1252   - English/US
even when I switch to different input language and type in characters in different languages

I think it should return different codepage number for different languages?
The LOCALE_RETURN_NUMBER flag only force the GetLocaleInfo-function to return CP in numeric (integer) form, instead of string form (which is default behavior), Without this flag you must change typ of 'langCP' from UINT to char[].

For thread_LCID=1033 is CP=1252, so it's o.k.

For just active input language try this:

HKL input_locale_identifier = GetKeyboardLayout(0);
LANGID language_identifier = LOWORD(input_locale_identifier);
LCID locale_identifier = MAKELCID(language_identifier, SORT_DEFAULT);
GetLocaleInfo(locale_identifier,...);

And for handling of dynamically changed keyboard layout you should process the WM_INPUTLANGCHANGE message.