mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 06:10:07 -04:00
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.
This commit is contained in:
committed by
Kirill Chibisov
parent
3930a6334f
commit
bd2b5cda8d
@@ -39,3 +39,7 @@ The migration guide could reference other migration examples in the current
|
|||||||
changelog entry.
|
changelog entry.
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- On Windows, fixed crash in should_apps_use_dark_mode() for Windows versions < 17763.
|
||||||
|
|||||||
@@ -132,7 +132,13 @@ fn should_apps_use_dark_mode() -> bool {
|
|||||||
static SHOULD_APPS_USE_DARK_MODE: Lazy<Option<ShouldAppsUseDarkMode>> = Lazy::new(|| unsafe {
|
static SHOULD_APPS_USE_DARK_MODE: Lazy<Option<ShouldAppsUseDarkMode>> = Lazy::new(|| unsafe {
|
||||||
const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL: PCSTR = 132 as PCSTR;
|
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 {
|
if module == 0 {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
Reference in New Issue
Block a user