From d8bd9189f82f6a9726ba02593a61401d3cf7bb66 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 21 Apr 2024 14:30:26 +0200 Subject: [PATCH] optimized last commit to not retrieve the function repeatedly if it has already failed. --- libraries/ZWidget/src/window/win32/win32window.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 64d4701ed..3ba21698a 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -275,10 +275,12 @@ typedef UINT(WINAPI* GetDpiForWindow_t)(HWND); double Win32Window::GetDpiScale() const { static GetDpiForWindow_t pGetDpiForWindow = nullptr; - if (!pGetDpiForWindow) + static bool done = false; + if (!done) { - HMODULE hMod = LoadLibrary(TEXT("User32.dll")); - pGetDpiForWindow = reinterpret_cast(GetProcAddress(hMod, "GetDpiForWindow")); + HMODULE hMod = GetModuleHandleA("User32.dll"); + if (hMod != nullptr) pGetDpiForWindow = reinterpret_cast(GetProcAddress(hMod, "GetDpiForWindow")); + done = true; } if (pGetDpiForWindow)