Solved

How do I get the country code

Posted on 2009-04-08
6
1,615 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now