Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argtypes of user32.GetWindowThreadProcessId need to be fixed #1

Open
bzczb opened this issue Feb 3, 2024 · 0 comments
Open

argtypes of user32.GetWindowThreadProcessId need to be fixed #1

bzczb opened this issue Feb 3, 2024 · 0 comments

Comments

@bzczb
Copy link

bzczb commented Feb 3, 2024

After a seemingly inconsequential change in my code, I started getting errors like this

Exception ignored on calling ctypes callback function: <function get_hwnd_from_pid.<locals>.callback at 0x0000021CFE28B380>
Traceback (most recent call last):
  File "c:\x\py_venv\Lib\site-packages\DearPyGui_DragAndDrop\tools.py", line 56, in callback
    user32.GetWindowThreadProcessId(hwnd, ctypes.byref(lpdw_PID))
ctypes.ArgumentError: argument 1: OverflowError: int too long to convert

Like many argtypes in Python on 64-bit Windows, the argtypes were broken for this function and it expected a 32-bit HWND. Not a problem normally because of the calling convention, except that Windows will sometimes give you extremely large HWNDs under obscure conditions.

Fix:
Changing the relevant section of tools.py fixed this

user32 = ctypes.windll.user32
WNDENUMPROC = ctypes.WINFUNCTYPE(wintypes.BOOL,
                                 wintypes.HWND,
                                 wintypes.LPARAM)
user32.EnumWindows.argtypes = [WNDENUMPROC,
                               wintypes.LPARAM]
user32.GetWindowThreadProcessId.restype = wintypes.DWORD
user32.GetWindowThreadProcessId.argtypes = [wintypes.HWND,
                                            wintypes.LPDWORD]

Reference: https://stackoverflow.com/a/37503441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant