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): [WayBack] How 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_IDEFAULTCODEPAGEto get the OEM code page for a locale.Bonus gotcha: There are a number of locales that are Unicode-only. If you ask the
GetLocaleInfofunction and ask for their ANSI and OEM code pages, the answer is “Um, I don’t have one.” (You get zero back.)
Related:
- [WayBack] windows – Why ANSI Code-Page and Console Code-Page are different? – Stack Overflow
- [WayBack] LOCALE_IDEFAULT* Constants – Windows applications | Microsoft Docs
- [WayBack] GetLocaleInfoA function | Microsoft Docs
- [WayBack] GetLocaleInfoW function | Microsoft Docs
- [WayBack] GetLocaleInfoEx function | Microsoft Docs
–jeroen






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)
jpluimers said
I’m not always in that luxury position (: