From d46f81afba0f7f3e49911bd6c481ab2a7b8b7a52 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Sat, 3 Aug 2019 21:52:05 +1000 Subject: [PATCH] Windows Screengrab DPI fix improvements (#2) * Load User32 after possible return * Removed unused setting of variable --- src/display.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/display.c b/src/display.c index 8611f3778..fd04804a2 100644 --- a/src/display.c +++ b/src/display.c @@ -332,8 +332,8 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) DWORD rop; PyObject* buffer; HANDLE dpiAwareness; - HMODULE user32 = LoadLibraryA("User32.dll"); - Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function; + HMODULE user32; + Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function; if (!PyArg_ParseTuple(args, "|i", &includeLayeredWindows)) return NULL; @@ -346,6 +346,7 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) // added in Windows 10 (1607) // loaded dynamically to avoid link errors + user32 = LoadLibraryA("User32.dll"); SetThreadDpiAwarenessContext_function = (Func_SetThreadDpiAwarenessContext) GetProcAddress(user32, "SetThreadDpiAwarenessContext"); @@ -358,7 +359,7 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) height = GetDeviceCaps(screen, VERTRES); if (SetThreadDpiAwarenessContext_function != NULL) { - dpiAwareness = SetThreadDpiAwarenessContext_function(dpiAwareness); + SetThreadDpiAwarenessContext_function(dpiAwareness); } FreeLibrary(user32);