`FormatMessage()` fails with specific system locales
On systems where the regional and language settings are derived from a common base language, e.g. English (Australia) from English (United Kingdom) or English (United States), the following call to the Windows API FormatMessageW()
or FormatMessageA()
to get the error message for the system locale, which is English (Australia), fails with ERROR_MUI_FILE_NOT_LOADED
or ERROR_MUI_FILE_NOT_FOUND
.
The following code is directly taken from Microsoft's C++ STL implementation of std::system_category::message()
https://github.com/microsoft/STL/blob/8b081e26ba016970ce3338cb483ff10f2ade30a5/stl/src/syserror_import_lib.cpp#L44:
DWORD _Lang_id;
const int _Ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER,
reinterpret_cast<LPWSTR>(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t));
const unsigned long _Chars =
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, _Message_id, _Lang_id, reinterpret_cast<char*>(_Ptr_str), 0, nullptr);
The problem persists, even if the correct language pack is installed.
Messages for system error codes are stored in KernelBase.dll.mui.
However, C:\Windows\System32\en-US\KernelBase.dll.mui exists for en-US, but not for the derived languages en-GB or en-AU.
Further inconsistencies are as follows: though the display language is configured to be English (Australia), the administrative dialog for "Welcome screen and new user account settings" are still set to a different language.
This is clearly either a bug in the Windows OS, or in the Windows API itself.
Where can we get assistance for it?