Skip to content

Commit d761a5f

Browse files
authored
Rollup merge of #114983 - crlf0710:formatmsg, r=ChrisDenton
Usage zero as language id for `FormatMessageW()` This switches the language selection from using system language (note that this might be different than application language, typically stored as thread ui language) to use `FormatMessageW` default search strategy, which is `neutral` first, then `thread ui lang`, then `user language`, then `system language`, then `English`. (See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagew) This allows the Rust program to take more control of `std::io::Error`'s message field, by setting up thread ui language themselves before hand (which many programs already do).
2 parents cbcdf75 + 4504cc5 commit d761a5f

File tree

1 file changed

+2
-6
lines changed
  • library/std/src/sys/windows

1 file changed

+2
-6
lines changed

library/std/src/sys/windows/os.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ pub fn errno() -> i32 {
2525

2626
/// Gets a detailed string description for the given error number.
2727
pub fn error_string(mut errnum: i32) -> String {
28-
// This value is calculated from the macro
29-
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
30-
let langId = 0x0800 as c::DWORD;
31-
3228
let mut buf = [0 as c::WCHAR; 2048];
3329

3430
unsafe {
@@ -56,13 +52,13 @@ pub fn error_string(mut errnum: i32) -> String {
5652
flags | c::FORMAT_MESSAGE_FROM_SYSTEM | c::FORMAT_MESSAGE_IGNORE_INSERTS,
5753
module,
5854
errnum as c::DWORD,
59-
langId,
55+
0,
6056
buf.as_mut_ptr(),
6157
buf.len() as c::DWORD,
6258
ptr::null(),
6359
) as usize;
6460
if res == 0 {
65-
// Sometimes FormatMessageW can fail e.g., system doesn't like langId,
61+
// Sometimes FormatMessageW can fail e.g., system doesn't like 0 as langId,
6662
let fm_err = errno();
6763
return format!("OS Error {errnum} (FormatMessageW() returned error {fm_err})");
6864
}

0 commit comments

Comments
 (0)