{"id":94475,"date":"2016-10-07T07:00:00","date_gmt":"2016-10-07T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94475"},"modified":"2019-03-13T10:32:21","modified_gmt":"2019-03-13T17:32:21","slug":"20161007-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20161007-00\/?p=94475","title":{"rendered":"How can I get the default code page for a locale?"},"content":{"rendered":"<p>A customer had an LCID and wanted to know what the code page is for that locale. For example, given locale 1033 (US-English), it should report that the code page is 1252 (Windows Latin 1). They need this information because the file format uses ANSI strings, and the file format for some reason doesn&#8217;t provide a code page, but does provide a locale. <\/p>\n<p>You can ask <code>Get&shy;Locale&shy;Info<\/code> for the <code>LOCALE_IDEFAULT&shy;ANSI&shy;CODE&shy;PAGE<\/code> to get the ANSI code page for a locale. <\/p>\n<pre>\nUINT GetAnsiCodePageForLocale(LCID lcid)\n{\n  UINT acp;\n  int sizeInChars = sizeof(acp) \/ sizeof(TCHAR);\n  if (GetLocaleInfo(lcid,\n                    LOCALE_IDEFAULTANSICODEPAGE |\n                    LOCALE_RETURN_NUMBER,\n                    reinterpret_cast&lt;LPTSTR&gt;(&amp;acp),\n                    sizeInChars) != sizeInChars) {\n    \/\/ Oops - something went wrong\n  }\n  return acp;\n}\n<\/pre>\n<p>This function uses the <code>LOCALE_RETURN_NUMBER<\/code> flag to say, &#8220;Hey, I know that the <code>Get&shy;Locale&shy;Info<\/code> function normally returns strings, and that&#8217;s great, but we both know that this thing I&#8217;m asking for is an integer (because the name beings with an <code>I<\/code>). Officially, you need to take that integer and convert it to a string, and officially I need to take that string and convert it back to an integer. How about <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20070529-01\/?p=26653\">let&#8217;s talk like people<\/a> and you just give me the integer directly?&#8221; <\/p>\n<p>And even though you didn&#8217;t ask, you can use <code>LOCALE_IDEFAULT&shy;CODE&shy;PAGE<\/code> to get the OEM code page for a locale. <\/p>\n<p><b>Bonus gotcha<\/b>: <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms930130.aspx\">There are a number of locales that are Unicode-only<\/a>. If you ask the <code>Get&shy;Locale&shy;Info<\/code> function and ask for their ANSI and OEM code pages, the answer is &#8220;Um, I don&#8217;t have one.&#8221; (You get zero back.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ask GetLocaleInfo.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-94475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Ask GetLocaleInfo.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=94475"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94475\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=94475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}