Thread: locale information on windows

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    locale information on windows

    On windows how can we determine the charset used by the application? On Unix we can use nl_langinfo(CODESET). Is there any similar mechanism on windows?

    TIA,
    Vivek.

  2. #2

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    I didnt get any function/mechanism for determining the codepage of application's locale. Most of the function descriptions talk about system default locale. My need is to get the code page of the locale used by the application. A more detailed help would be of great help.

    TIA,
    Vivek

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Your application uses the "C" locale by default ( 7 Bit ASCII ).

    You can query your codepage by using the returnvalue of the setlocale function;

    Code:
    char* loc = setlocale( LC_ALL, NULL );
    or MS Unicode specific macros:

    Code:
    LPTSTR lpszCodePage = _tsetlocale( LC_ALL, NULL );
    You can set the applications codepage to the current windows codepage by passing an empty string:

    Code:
    char* loc = setlocale( LC_ALL, "" );
    MS Unicode Macros:

    Code:
    LPTSTR lpszCodePage = _tsetlocale( LC_ALL, _T("") );
    You can also pass any codepage name to select that codepage for your application.

    More info here
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Well, GetCPInfo() is in that section of MSDN but they talk about it any.

    Use the "See Also" links, TOC pane on the left, and the search feature on MSDN to dig in further.

    Using standard C functions is an option as well - as nvoigt has shown.

    gg

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by techi_talk
    I didnt get any function/mechanism for determining the codepage of application's locale. Most of the function descriptions talk about system default locale. My need is to get the code page of the locale used by the application.
    It depends on what exactly you are trying to do. It sounds like you are looking for the thread code page. This can be determined by calling GetThreadLocale followed by GetLocaleInfo with LOCALE_IDEFAULTANSICODEPAGE.

    However, this is not the end of the matter. The C runtime library may use another code page. This can be determined with setlocale and _getmbcp.

    The system code page may differ from the current thread code page. Some functions use the system code page rather than the thread code page as the concept of thread specific code pages was only introduced in 2000/XP. The system code page can be obtained with GetACP.

    If the file system uses FAT rather than NTFS (which uses unicode), then it too may use a different code page. This can be obtained with GetOEMCP.

    The console may use different code pages. These can be obtained with GetConsoleCP and GetConsoleOutputCP.

    All of this should not be confused with the preferred user interface language which can be obtained with GetUserDefaultUILanguage.

    It is strongly recommended that you avoid this mess and make use of unicode. Unicode is supported natively on NT/2000/XP and with the help of the Microsoft Layer for Unicode on 9x.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Windows Rant followed by installation question
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-21-2003, 04:42 PM
  3. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  4. How come this only works in Windows nt/2000?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-30-2002, 06:54 PM