Skip to content

Commit 0d01efc

Browse files
Slartibartyslouken
authored andcommitted
windows: Fix crash when using a system that reports itself as Windows 17763 or newer, but is missing many of the newer dark mode window functions (Linux Mint Cinnamon w/ Proton 7.0.6)
(cherry picked from commit 0a50b79)
1 parent 0e65e04 commit 0d01efc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/video/windows/SDL_windowswindow.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,38 +2220,38 @@ bool WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool foc
22202220
void WIN_UpdateDarkModeForHWND(HWND hwnd)
22212221
{
22222222
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
2223-
SDL_SharedObject *ntdll = SDL_LoadObject("ntdll.dll");
2223+
HMODULE ntdll = LoadLibrary(TEXT("ntdll.dll"));
22242224
if (!ntdll) {
22252225
return;
22262226
}
22272227
// There is no function to get Windows build number, so let's get it here via RtlGetVersion
2228-
RtlGetVersion_t RtlGetVersionFunc = (RtlGetVersion_t)SDL_LoadFunction(ntdll, "RtlGetVersion");
2228+
RtlGetVersion_t RtlGetVersionFunc = (RtlGetVersion_t)GetProcAddress(ntdll, "RtlGetVersion");
22292229
NT_OSVERSIONINFOW os_info;
22302230
os_info.dwOSVersionInfoSize = sizeof(NT_OSVERSIONINFOW);
22312231
os_info.dwBuildNumber = 0;
22322232
if (RtlGetVersionFunc) {
22332233
RtlGetVersionFunc(&os_info);
22342234
}
2235-
SDL_UnloadObject(ntdll);
2235+
FreeLibrary(ntdll);
22362236
os_info.dwBuildNumber &= ~0xF0000000;
22372237
if (os_info.dwBuildNumber < 17763) {
22382238
// Too old to support dark mode
22392239
return;
22402240
}
2241-
SDL_SharedObject *uxtheme = SDL_LoadObject("uxtheme.dll");
2241+
HMODULE uxtheme = LoadLibrary(TEXT("uxtheme.dll"));
22422242
if (!uxtheme) {
22432243
return;
22442244
}
2245-
RefreshImmersiveColorPolicyState_t RefreshImmersiveColorPolicyStateFunc = (RefreshImmersiveColorPolicyState_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(104));
2246-
ShouldAppsUseDarkMode_t ShouldAppsUseDarkModeFunc = (ShouldAppsUseDarkMode_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(132));
2247-
AllowDarkModeForWindow_t AllowDarkModeForWindowFunc = (AllowDarkModeForWindow_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(133));
2245+
RefreshImmersiveColorPolicyState_t RefreshImmersiveColorPolicyStateFunc = (RefreshImmersiveColorPolicyState_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(104));
2246+
ShouldAppsUseDarkMode_t ShouldAppsUseDarkModeFunc = (ShouldAppsUseDarkMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(132));
2247+
AllowDarkModeForWindow_t AllowDarkModeForWindowFunc = (AllowDarkModeForWindow_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(133));
22482248
if (os_info.dwBuildNumber < 18362) {
2249-
AllowDarkModeForApp_t AllowDarkModeForAppFunc = (AllowDarkModeForApp_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(135));
2249+
AllowDarkModeForApp_t AllowDarkModeForAppFunc = (AllowDarkModeForApp_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
22502250
if (AllowDarkModeForAppFunc) {
22512251
AllowDarkModeForAppFunc(true);
22522252
}
22532253
} else {
2254-
SetPreferredAppMode_t SetPreferredAppModeFunc = (SetPreferredAppMode_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(135));
2254+
SetPreferredAppMode_t SetPreferredAppModeFunc = (SetPreferredAppMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
22552255
if (SetPreferredAppModeFunc) {
22562256
SetPreferredAppModeFunc(UXTHEME_APPMODE_ALLOW_DARK);
22572257
}
@@ -2269,7 +2269,7 @@ void WIN_UpdateDarkModeForHWND(HWND hwnd)
22692269
} else {
22702270
value = (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK) ? TRUE : FALSE;
22712271
}
2272-
SDL_UnloadObject(uxtheme);
2272+
FreeLibrary(uxtheme);
22732273
if (os_info.dwBuildNumber < 18362) {
22742274
SetProp(hwnd, TEXT("UseImmersiveDarkModeColors"), SDL_reinterpret_cast(HANDLE, SDL_static_cast(INT_PTR, value)));
22752275
} else {

0 commit comments

Comments
 (0)