Skip to content

Commit d8bd918

Browse files
coelckersmadame-rachelle
authored andcommitted
optimized last commit to not retrieve the function repeatedly if it has already failed.
1 parent 0da6e76 commit d8bd918

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

libraries/ZWidget/src/window/win32/win32window.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ typedef UINT(WINAPI* GetDpiForWindow_t)(HWND);
275275
double Win32Window::GetDpiScale() const
276276
{
277277
static GetDpiForWindow_t pGetDpiForWindow = nullptr;
278-
if (!pGetDpiForWindow)
278+
static bool done = false;
279+
if (!done)
279280
{
280-
HMODULE hMod = LoadLibrary(TEXT("User32.dll"));
281-
pGetDpiForWindow = reinterpret_cast<GetDpiForWindow_t>(GetProcAddress(hMod, "GetDpiForWindow"));
281+
HMODULE hMod = GetModuleHandleA("User32.dll");
282+
if (hMod != nullptr) pGetDpiForWindow = reinterpret_cast<GetDpiForWindow_t>(GetProcAddress(hMod, "GetDpiForWindow"));
283+
done = true;
282284
}
283285

284286
if (pGetDpiForWindow)

0 commit comments

Comments
 (0)