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_IDEFAULTCODEPAGE
to get the OEM code page for a locale.Bonus gotcha: There are a number of locales that are Unicode-only. If you ask the
GetLocaleInfo
function 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