From fa51112a5aa66137cc1aa24b3b35131608cd027d Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 1 May 2022 17:20:16 +0700 Subject: [PATCH] : explicitly pass the system locale ID for system_category messages (#2669) --- stl/src/syserror_import_lib.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stl/src/syserror_import_lib.cpp b/stl/src/syserror_import_lib.cpp index 8f8046d48..88db62630 100644 --- a/stl/src/syserror_import_lib.cpp +++ b/stl/src/syserror_import_lib.cpp @@ -45,9 +45,15 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message( // convert to name of Windows error, return 0 for failure, otherwise return number of chars in buffer // __std_system_error_deallocate_message should be called even if 0 is returned // pre: *_Ptr_str == nullptr + DWORD _Lang_id; + const int _Ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER, + reinterpret_cast(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t)); + if (_Ret == 0) { + _Lang_id = 0; + } const unsigned long _Chars = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, _Message_id, 0, reinterpret_cast(_Ptr_str), 0, nullptr); + nullptr, _Message_id, _Lang_id, reinterpret_cast(_Ptr_str), 0, nullptr); return _CSTD __std_get_string_size_without_trailing_whitespace(*_Ptr_str, _Chars); }