The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,649 other followers

How can I get the default code page for a locale? – The Old New Thing

Posted by jpluimers on 2017/06/20

Ask GetLocaleInfo (example function GetAnsiCodePageForLocale included): [WayBackHow can I get the default code page for a locale? – The Old New Thing

UINT GetAnsiCodePageForLocale(LCID lcid)
{
  UINT acp;
  int sizeInChars = sizeof(acp) / sizeof(TCHAR);
  if (GetLocaleInfo(lcid,
                    LOCALE_IDEFAULTANSICODEPAGE |
                    LOCALE_RETURN_NUMBER,
                    reinterpret_cast<LPTSTR>(&acp),
                    sizeInChars) != sizeInChars) {
    // Oops - something went wrong
  }
  return acp;
}

And even though you didn’t ask, you can use LOCALE_IDEFAULT­CODE­PAGE to get the OEM code page for a locale.

Bonus gotchaThere are a number of locales that are Unicode-only. If you ask the Get­Locale­Info function and ask for their ANSI and OEM code pages, the answer is “Um, I don’t have one.” (You get zero back.)

Related:

–jeroen

2 Responses to “How can I get the default code page for a locale? – The Old New Thing”

  1. ruurd said

    Just fuck it. If it ain’t UTF-8 then crawl back in your cave until you can think straight again. Codepages are The Wrong Thing(TM)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: