Solved

How do I get the country code

Posted on 2009-04-08
6
1,673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 82
My project did see openJDK that I installed. What could be the problem 7 171
Problem to event 3 123
PHPStorm debugging issues 1 95
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

734 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