Skip to content

Commit

Permalink
Merge pull request #26 from nulano/imagegrab-dynamic-link
Browse files Browse the repository at this point in the history
Fix GetWindowDpiAwarenessContext NULL check
  • Loading branch information
radarhere authored Nov 8, 2024
2 parents 288d77e + acba5c4 commit c5e89ee
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
HWND wnd;
DWORD rop;
PyObject *buffer;
HANDLE dpiAwareness;
HANDLE dpiAwareness = NULL;
HMODULE user32;
Func_GetWindowDpiAwarenessContext GetWindowDpiAwarenessContext_function;
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;
Expand Down Expand Up @@ -360,22 +360,15 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
SetThreadDpiAwarenessContext_function = (Func_SetThreadDpiAwarenessContext
)GetProcAddress(user32, "SetThreadDpiAwarenessContext");
if (SetThreadDpiAwarenessContext_function != NULL) {
if (screens == -1) {
GetWindowDpiAwarenessContext_function = (Func_GetWindowDpiAwarenessContext
)GetProcAddress(user32, "GetWindowDpiAwarenessContext");
DPI_AWARENESS_CONTEXT dpiAwarenessContext =
GetWindowDpiAwarenessContext_function(wnd);
if (GetWindowDpiAwarenessContext_function != NULL &&
dpiAwarenessContext != NULL) {
dpiAwareness =
SetThreadDpiAwarenessContext_function(dpiAwarenessContext);
} else {
dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE)-3);
}
} else {
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE)-3);
GetWindowDpiAwarenessContext_function = (Func_GetWindowDpiAwarenessContext
)GetProcAddress(user32, "GetWindowDpiAwarenessContext");
if (screens == -1 && GetWindowDpiAwarenessContext_function != NULL) {
dpiAwareness = GetWindowDpiAwarenessContext_function(wnd);
}
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
dpiAwareness = SetThreadDpiAwarenessContext_function(
dpiAwareness == NULL ? (HANDLE)-3 : dpiAwareness
);
}

if (screens == 1) {
Expand Down

0 comments on commit c5e89ee

Please sign in to comment.