Solved

How do I get the country code

Posted on 2009-04-08
6
1,644 Views
Last Modified: 2013-11-23
Windows defines these constants: CTRY_AUSTRALIA, CTRY_AUSTRIA, CTRY_BELGIUM, etc.  The GetLocaleInfo returns strings for local configurations.  I have looked around and everyone uses GetLocaleInfo to obtain string values.

Which function should I call to get the CTRY_AUSTRALIA, CTRY_AUSTRIA, CTRY_BELGIUM constants?

Thanks
0
Comment
Question by:rambolivia
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 24099097
You can get that valus (as a string, though) by calling 'GetLocaleInfo()' and requesting LOCALE_ICOUNTRY - here's a small C sample that demonstrates this:
#include <windows.h>
#include <stdio.h>
 
void main () {
 
  char buf[255];
 
  GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_ICOUNTRY,buf,255);
 
  printf("%s\n",buf);
}

Open in new window

0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 100 total points
ID: 24099133
>>>> Which function should I call to get the CTRY_AUSTRALIA

Hmm. These are 'region codes' which were used for phone numbers to these countries.

You can find your region code in the registry at

   HKEY_CURRENT_USER\Control Panel\International  

in the Value 'iCountry'.

I doubt that there is an official API for it. In MSDN I found only functions of 'Commerce Server 2002'  which retrieve that value - what ever that is.

But by calling RegQueryValue you surely can get it.

 
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24099161
>>>> I doubt that there is an official API for it.

jkr knows better ;-)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24099209
>>>> Which function should I call to get the CTRY_AUSTRALIA, CTRY_AUSTRIA, CTRY_BELGIUM constants?

You would get the 61 == CTRY_AUSTRALIA as string value.

To get the name 'Australia' you probably would need LOCALE_SCOUNTRY as input constant.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 24099445
These constants are defined in Winnls.h http://www.krugle.org/kse/entcodespaces/DpcALR , include Window.h to get their values as in the code snippet below.

You might however be actually looking for what jkr specified above, the "Language Identifiers and Locales" might be useful http://msdn.microsoft.com/en-us/library/ms903928.aspx if you need to explicitly set the locale. Also check out "Local Information Constants" http://msdn.microsoft.com/en-us/library/dd464799(VS.85).aspx

#include <iostream>
#include "Windows.h"
 
using namespace std;
 
int main()
{
  cout << "CTRY_AUSTRALIA\t" << CTRY_AUSTRALIA << endl;
  cout << "CTRY_AUSTRIA\t" << CTRY_AUSTRIA << endl;
  cout << "CTRY_BELGIUM\t" << CTRY_BELGIUM << endl;
 
  system("pause");
 
  return 0;
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:rambolivia
ID: 31568070
The registry entries are good and valid even in Windows 64bits and Windows Vista.  The Delphi code I decided to use is:

procedure GetCurrentCountryInformation(out CountryCode: integer; out CountryName: string);
var
  ret: DWORD;
  info: DWORD;
  buff: Array[0..255] of  WideChar;
begin
  CountryCode := 0;
  CountryName := '';

  ret := GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, @buff, 256);

  if (ret = 0) then
  exit;

  CountryCode := StrToInt(buff);

  ret := GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SCOUNTRY, @buff, 256);

  if (ret = 0) then
  exit;

  CountryName :=  buff;
end;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

828 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