Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I get the country code

Posted on 2009-04-08
6
Medium Priority
?
1,732 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 450 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 300 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

916 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