From ed4ebd4242bac14b4ff4889bfab31dff05ee0ae9 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 | 1 + src/platform_impl/windows/dark_mode.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 2198bb7f..a8df3c34 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -246,3 +246,4 @@ changelog entry. - On macOS, fixed the scancode conversion for audio volume keys. - On macOS, fixed the scancode conversion for `IntlBackslash`. - On macOS, fixed redundant `SurfaceResized` event at window creation. +- 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 6d50e308..a2226f5b 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -133,6 +133,12 @@ fn should_apps_use_dark_mode() -> bool { LazyLock::new(|| unsafe { const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL: PCSTR = 132 as PCSTR; + // 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(c"uxtheme.dll".as_ptr().cast()); if module.is_null() {