Solved

How do I get the country code

Posted on 2009-04-08
6
1,640 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

777 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