Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get current codepage?

Posted on 2004-09-07
13
Medium Priority
?
1,526 Views
Last Modified: 2013-12-03
How can I findout what codepage is currntly used by user?
0
Comment
Question by:serg111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12002310
0
 
LVL 2

Author Comment

by:serg111
ID: 12002589
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
 
LVL 7

Expert Comment

by:jimwasson
ID: 12003112
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 2

Author Comment

by:serg111
ID: 12003359
In which DLL is this function? I cant find it on my computer with WinXP :-(
0
 
LVL 7

Expert Comment

by:jimwasson
ID: 12005540
It's in the C runtime libraries. You might need to include the header file mbctype.h.
0
 
LVL 2

Author Comment

by:serg111
ID: 12006741
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
 
LVL 7

Expert Comment

by:jimwasson
ID: 12007098
Borland C -- which version exactly?
0
 
LVL 2

Author Comment

by:serg111
ID: 12009196
This is Version 5.02

0
 

Accepted Solution

by:
hupe earned 1000 total points
ID: 12014873
You can get codepage from LCID with this function:

UINT langCP;
GetLocaleInfo(langLCID, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (LPTSTR) &langCP, sizeof(UINT));
0
 
LVL 2

Author Comment

by:serg111
ID: 12015657
I've got 2 errors with this code :-(

undefined symbol: langLCID
undefined symbol: LOCALE_RETURN_NUMBER
0
 

Expert Comment

by:hupe
ID: 12018870
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
 
LVL 2

Author Comment

by:serg111
ID: 12019268
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
 

Expert Comment

by:hupe
ID: 12024791
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question