• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1576
  • Last Modified:

How to get current codepage?

How can I findout what codepage is currntly used by user?
0
serg111
Asked:
serg111
  • 6
  • 3
  • 3
  • +1
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
0
 
serg111Author Commented:
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\
0
 
jimwassonCommented:
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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
serg111Author Commented:
In which DLL is this function? I cant find it on my computer with WinXP :-(
0
 
jimwassonCommented:
It's in the C runtime libraries. You might need to include the header file mbctype.h.
0
 
serg111Author Commented:
I am using borland C and it doesn't have this function in mbctype.h
Do you know what library does contain this function?
0
 
jimwassonCommented:
Borland C -- which version exactly?
0
 
serg111Author Commented:
This is Version 5.02

0
 
hupeCommented:
You can get codepage from LCID with this function:

UINT langCP;
GetLocaleInfo(langLCID, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (LPTSTR) &langCP, sizeof(UINT));
0
 
serg111Author Commented:
I've got 2 errors with this code :-(

undefined symbol: langLCID
undefined symbol: LOCALE_RETURN_NUMBER
0
 
hupeCommented:
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().
0
 
serg111Author Commented:
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?
0
 
hupeCommented:
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now