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

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

Hello Eryk,
thank you for your interest in my problem and you've nailed it, the problem
was solved by putting all Windows API definitions in a separate module and
making sure that I only use WinDLL.
I would never have thought of that, because I only used WinDLL in this
But a PostMessage in another module, which I created with windll, seems to
have confused things a bit and now that I have merged this and other
modules into one, I don't see the problem anymore.
Here is the desired excerpt. (user32 is now import from win32api, where all
other definitions are now also)

    def new_scintilla2_proc(self, hWnd, msg, wParam, lParam):
        if self.__WndProc(hWnd, msg, wParam, lParam):
            return 0

        print(f'{hWnd=}, {msg=}, {wParam=}, {lParam=}')
        return user32.CallWindowProcW(self.prev_scintilla2_wnd_proc, hWnd,
msg, wParam, lParam)

    def __WndProc(self, hWnd, msg, wParam, lParam):
        event_handler = self._event_handler.get(msg, None)
        if event_handler:
            return event_handler(msg, wParam, lParam)
        return False

Once again, thank you

Am Mi., 29. Juli 2020 um 16:26 Uhr schrieb Eryk Sun <eryksun at>:

> On 7/28/20, Eko palypse <ekopalypse at> wrote:
> >
> > 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
> Can you provide a more complete example of how you're calling
> CallWindowProcW in new_scintilla2_proc? It seems like a function
> pointer is being called that doesn't have argtypes defined. For
> example:
>     >>> user32 = ctypes.WinDLL('user32', use_last_error=True)
>     >>> user32.CallWindowProcW(None, None, 0x14, 18446744072652653190, 0)
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     ctypes.ArgumentError: argument 4: <class 'OverflowError'>: int too
> long to convert
> Perhaps in new_scintilla2_proc you're using a different instance of
> ctypes.WinDLL, or you switched to using ctypes.windll.user32. I
> recommend avoiding the global ctypes.LibraryLoader instances --
> ctypes.cdll, ctypes.windll, and ctypes.oledll -- because using them
> leads to conflicts with other libraries, but you do need to use a
> single instance of ctypes.WinDLL for your user32 function prototypes,
> imported from a common module.