git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Windows and Subclassing - 'OverflowError': int too long to convert


Hello,
I am subclassing a scintilla window and it happens every now and then
that I get an OverflowError. I've logged the message and could narrow down
that it
is a single windows message which causes this trouble. It's WM_ERASEBKGND.

Now the confusing part for me is the following.
According to MS WPARAM
<https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types> is
an UINT_PTR which is defined as

#if defined(_WIN64) typedef unsigned __int64 UINT_PTR; #else typedef
unsigned int UINT_PTR; #endif

wintypes.WPARAM is ctypes.c_ulonglong and is of size 8 on my system.
I'm on a x64 Windows - so far as good, right?

Now when I get this error the message I receive in this situation is always
like this.

hWnd=197364, msg=20, wParam=*18446744072652653190*, lParam=0

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 237, in 'calling callback function'
  File "<string>", line 121, in new_scintilla2_proc
ctypes.ArgumentError: argument 4: <class 'OverflowError'>: int too long to
convert

I really doubt that 18446744072652653190 is a valid device context but who
knows.
The question is, why do I even get this OverflowError?

If I do wintypes.WPARAM(18446744072652653190) I don't receive an exception
and it is a valid 64bit value, isn't it?

The code I'm using is this

user32 = ctypes.WinDLL('user32', use_last_error=True)

LRESULT = wintypes.LPARAM
WND_PROC = ctypes.WINFUNCTYPE(LRESULT,
                              wintypes.HWND,
                              wintypes.UINT,
                              wintypes.WPARAM,
                              wintypes.LPARAM)

user32.CallWindowProcW.restype = LRESULT
user32.CallWindowProcW.argtypes = [WND_PROC,
                                   wintypes.HWND,
                                   wintypes.UINT,
                                   wintypes.WPARAM,
                                   wintypes.LPARAM]


Any idea what might have caused this?

Thank you for reading
Eren