Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #8383

The Dib class passes handle to core method getdc() in expose()

Pillow/src/PIL/ImageWin.py

Lines 101 to 102 in b67f018

if isinstance(handle, HWND):
dc = self.image.getdc(handle)

but despite what our Python logic would lead you to expect, it must be an integer. See the following code and https://docs.python.org/3/c-api/arg.html#numbers

Pillow/src/display.c

Lines 37 to 41 in b67f018

#if SIZEOF_VOID_P == 8
#define F_HANDLE "K"
#else
#define F_HANDLE "k"
#endif

Pillow/src/display.c

Lines 165 to 169 in b67f018

_getdc(ImagingDisplayObject *display, PyObject *args) {
HWND window;
HDC dc;
if (!PyArg_ParseTuple(args, F_HANDLE, &window)) {

So this PR casts it to an integer in Python first. The same logic also applies to draw() and query_palette().

@hugovk hugovk merged commit f85c8dc into python-pillow:main Sep 16, 2024
@radarhere radarhere deleted the dib_hwnd branch September 16, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: argument 1 must be int, not HWND

2 participants