Skip to content

Commit 0a50b79

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)
1 parent 2d8fd6b commit 0a50b79

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
@@ -2301,38 +2301,38 @@ bool WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool foc
23012301
void WIN_UpdateDarkModeForHWND(HWND hwnd)
23022302
{
23032303
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
2304-
SDL_SharedObject *ntdll = SDL_LoadObject("ntdll.dll");
2304+
HMODULE ntdll = LoadLibrary(TEXT("ntdll.dll"));
23052305
if (!ntdll) {
23062306
return;
23072307
}
23082308
// There is no function to get Windows build number, so let's get it here via RtlGetVersion
2309-
RtlGetVersion_t RtlGetVersionFunc = (RtlGetVersion_t)SDL_LoadFunction(ntdll, "RtlGetVersion");
2309+
RtlGetVersion_t RtlGetVersionFunc = (RtlGetVersion_t)GetProcAddress(ntdll, "RtlGetVersion");
23102310
NT_OSVERSIONINFOW os_info;
23112311
os_info.dwOSVersionInfoSize = sizeof(NT_OSVERSIONINFOW);
23122312
os_info.dwBuildNumber = 0;
23132313
if (RtlGetVersionFunc) {
23142314
RtlGetVersionFunc(&os_info);
23152315
}
2316-
SDL_UnloadObject(ntdll);
2316+
FreeLibrary(ntdll);
23172317
os_info.dwBuildNumber &= ~0xF0000000;
23182318
if (os_info.dwBuildNumber < 17763) {
23192319
// Too old to support dark mode
23202320
return;
23212321
}
2322-
SDL_SharedObject *uxtheme = SDL_LoadObject("uxtheme.dll");
2322+
HMODULE uxtheme = LoadLibrary(TEXT("uxtheme.dll"));
23232323
if (!uxtheme) {
23242324
return;
23252325
}
2326-
RefreshImmersiveColorPolicyState_t RefreshImmersiveColorPolicyStateFunc = (RefreshImmersiveColorPolicyState_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(104));
2327-
ShouldAppsUseDarkMode_t ShouldAppsUseDarkModeFunc = (ShouldAppsUseDarkMode_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(132));
2328-
AllowDarkModeForWindow_t AllowDarkModeForWindowFunc = (AllowDarkModeForWindow_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(133));
2326+
RefreshImmersiveColorPolicyState_t RefreshImmersiveColorPolicyStateFunc = (RefreshImmersiveColorPolicyState_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(104));
2327+
ShouldAppsUseDarkMode_t ShouldAppsUseDarkModeFunc = (ShouldAppsUseDarkMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(132));
2328+
AllowDarkModeForWindow_t AllowDarkModeForWindowFunc = (AllowDarkModeForWindow_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(133));
23292329
if (os_info.dwBuildNumber < 18362) {
2330-
AllowDarkModeForApp_t AllowDarkModeForAppFunc = (AllowDarkModeForApp_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(135));
2330+
AllowDarkModeForApp_t AllowDarkModeForAppFunc = (AllowDarkModeForApp_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
23312331
if (AllowDarkModeForAppFunc) {
23322332
AllowDarkModeForAppFunc(true);
23332333
}
23342334
} else {
2335-
SetPreferredAppMode_t SetPreferredAppModeFunc = (SetPreferredAppMode_t)SDL_LoadFunction(uxtheme, MAKEINTRESOURCEA(135));
2335+
SetPreferredAppMode_t SetPreferredAppModeFunc = (SetPreferredAppMode_t)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135));
23362336
if (SetPreferredAppModeFunc) {
23372337
SetPreferredAppModeFunc(UXTHEME_APPMODE_ALLOW_DARK);
23382338
}
@@ -2350,7 +2350,7 @@ void WIN_UpdateDarkModeForHWND(HWND hwnd)
23502350
} else {
23512351
value = (SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK) ? TRUE : FALSE;
23522352
}
2353-
SDL_UnloadObject(uxtheme);
2353+
FreeLibrary(uxtheme);
23542354
if (os_info.dwBuildNumber < 18362) {
23552355
SetProp(hwnd, TEXT("UseImmersiveDarkModeColors"), SDL_reinterpret_cast(HANDLE, SDL_static_cast(INT_PTR, value)));
23562356
} else {

0 commit comments

Comments
 (0)