From bd2b5cda8d5d843a1771341e1aa7b33c91495c0a Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Wed, 14 May 2025 20:31:48 +0800 Subject: [PATCH] windows: Fix crash in for Windows versions < 17763 In Windows versions < 17763, `GetProcAddress("#132")` from `uxtheme.dll` also returns a non-null pointer. However, the function does not match the expected `extern "system" fn() -> bool` prototype, which causes a crash when it is called. This fix ensures compatibility by adding proper checks to prevent such crashes on older Windows versions. --- src/changelog/unreleased.md | 4 ++++ src/platform_impl/windows/dark_mode.rs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index f3a0f6d2c..5a50389ae 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -39,3 +39,7 @@ The migration guide could reference other migration examples in the current changelog entry. ## Unreleased + +### Fixed + +- On Windows, fixed crash in should_apps_use_dark_mode() for Windows versions < 17763. diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index 9d4bad927..366e44c68 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -132,7 +132,13 @@ fn should_apps_use_dark_mode() -> bool { static SHOULD_APPS_USE_DARK_MODE: Lazy> = Lazy::new(|| unsafe { const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL: PCSTR = 132 as PCSTR; - let module = LoadLibraryA("uxtheme.dll\0".as_ptr()); + // We won't try to do anything for windows versions < 17763 + // (Windows 10 October 2018 update) + if !*DARK_MODE_SUPPORTED { + return None; + } + + let module = LoadLibraryA("uxtheme.dll\0".as_ptr().cast()); if module == 0 { return None;