optimized last commit to not retrieve the function repeatedly if it has already failed.

This commit is contained in:
Christoph Oelckers 2024-04-21 14:30:26 +02:00 committed by Rachael Alexanderson
parent 51b3e4b335
commit 260c019301
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0

View file

@ -275,10 +275,12 @@ typedef UINT(WINAPI* GetDpiForWindow_t)(HWND);
double Win32Window::GetDpiScale() const double Win32Window::GetDpiScale() const
{ {
static GetDpiForWindow_t pGetDpiForWindow = nullptr; static GetDpiForWindow_t pGetDpiForWindow = nullptr;
if (!pGetDpiForWindow) static bool done = false;
if (!done)
{ {
HMODULE hMod = LoadLibrary(TEXT("User32.dll")); HMODULE hMod = GetModuleHandleA("User32.dll");
pGetDpiForWindow = reinterpret_cast<GetDpiForWindow_t>(GetProcAddress(hMod, "GetDpiForWindow")); if (hMod != nullptr) pGetDpiForWindow = reinterpret_cast<GetDpiForWindow_t>(GetProcAddress(hMod, "GetDpiForWindow"));
done = true;
} }
if (pGetDpiForWindow) if (pGetDpiForWindow)