Jump to content
  • Advertisement
Sign in to follow this  
whitde

How to get Country of local machine?

This topic is 5026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I update a highscore database on the Internet for my hame but would like to also store the Country. Is there a way in Windows to painlessly get the Country without prompting the user? I was going to use the IP address and do a Country lookup but that's a real pain... not quite as simple as I thought. Would be ideal if the function returned "us", "au","nz","ru"...etc. I'm sure storing the Country with the high scores would create a bit of inter-Country rivalry for the top 20 high scores. It would also let mess see where people using the game are from.

Share this post


Link to post
Share on other sites
Advertisement
This code seems to work for me:

char szBuff[32];
GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SCOUNTRY,szBuff,32);


Which gives "United Kingom" in szBuff. Using LOCALE_SYSTEM_DEFAULT gives "United States", which is wrong.
If you want that string as a 2 letter string (e.h. "uk", "us", "nz", etc), you could have some sort of mapping table to convert "United States" to "us" and so on.

Share this post


Link to post
Share on other sites
Quote:
... the default.
Which was the UK when I installed windows (hence the being in the UK part) So I'd say its quite reliable.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!