From 7f6785f36336671b01ba9944cf7101a7c2c487bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 22 Apr 2023 14:38:05 +0200 Subject: [PATCH] win32: explicitly guard dark mode calls by Windows version Fixes: #11610 Fixes: 9feeb324eddd9ed73ae667e10275f663d70f7544 --- video/out/w32_common.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index b6da8223c4..b3ad949794 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -1552,8 +1552,20 @@ static void w32_api_load(struct vo_w32_state *w32) w32->api.pImmDisableIME = !imm32_dll ? NULL : (void *)GetProcAddress(imm32_dll, "ImmDisableIME"); - // Dark mode related functions, avaliable since a Win10 update - HMODULE uxtheme_dll = GetModuleHandle(L"uxtheme.dll"); + // Dark mode related functions, available since the 1809 Windows 10 update + // Check the Windows build version as on previous versions used ordinals + // may point to unexpected code/data. Alternatively could check uxtheme.dll + // version directly, but it is little bit more boilerplate code, and build + // number is good enough check. + void (WINAPI *pRtlGetNtVersionNumbers)(LPDWORD, LPDWORD, LPDWORD) = + (void *)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetNtVersionNumbers"); + + DWORD major, build; + pRtlGetNtVersionNumbers(&major, NULL, &build); + build &= ~0xF0000000; + + HMODULE uxtheme_dll = (major < 10 || build < 17763) ? NULL : + GetModuleHandle(L"uxtheme.dll"); w32->api.pShouldAppsUseDarkMode = !uxtheme_dll ? NULL : (void *)GetProcAddress(uxtheme_dll, MAKEINTRESOURCEA(132)); w32->api.pSetPreferredAppMode = !uxtheme_dll ? NULL :