When pywinauto uses “ctypes” to call the same system function with other modules ,it will cause the ctypes.ArgumentError
See original GitHub issueSteps to Reproduce the Problem
import pywinauto- import other module which using ctypes to call the same system function
Actual Behavior
return bool(ctypes.windll.user32.IsWindowVisible(ctypes.c_void_p(handle)))
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Expected Behavior
If I delete the the argtypes and restype in win32functions.py, for example
IsWindowVisible.argtypes = [win32structures.HWND]
IsWindowVisible.restype = win32structures.BOOL ,
everything seems to go well.
Short Example of Code to Demonstrate the Problem
from pywinauto.application import Application
import uiautomation as auto
from data.setting import Setting
window = auto.WindowControl(AutomationId="mywindowautoid",Name="mywindowname",searchDepth =1)
window.SetActive()
app = Application(backend="uia").connect(path=Setting.exepath)
print(app.is_process_running())
Specifications
- Pywinauto version: the lastest version 0.6.6
- Python version and bitness: 3.7.2 and 32bit
- Platform and OS: Win10
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
ctypes.ArgumentError when using kivy with pywinauto
Both modules call this function via ctypes: ... Kivy tried to call the function using Pywinauto's prototype, otherwise it would have worked.
Read more >Issues · pywinauto/pywinauto · GitHub
When pywinauto uses “ctypes” to call the same system function with other modules ,it will cause the ctypes.ArgumentError need investigation.
Read more >pywinauto wrapper_object | The Search Engine You Control
An HwndWrapper object can be passed directly to a ctypes wrapped C function - and it will get converted to a Long with...
Read more >2009-October.txt - Python mailing list
I started this for the first few methods of the IRealTimeStylus interface: """ # module realtimestylus.py from ctypes import * from ctypes.wintypes import ......
Read more >PyInstaller Documentation - Read the Docs
When you install PyInstaller using pip, the setup will attempt to build a ... Ctypes is a foreign function library for Python, that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Pywinauto sets up the return type of
GetWindowtowintypes.HWNDas per https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindow The xlwings problem seems to be due to this line in _xlwings.py: https://github.com/xlwings/xlwings/blob/4a51d73b87af3820fc686b402e65e0c843e9d63c/xlwings/_xlwindows.py#L300 because thec_void_pis casted to Pythonlongtype instead ofintegerreturned by ctypes restype by default. Limiting restype to integer is dangerous, especially on 64-bit OS, because HWND can exceed the integer type max size, which I believe is 32-bits for Python 2.7 (see:sys.maxint)I encountered the same problem using the xlwings package.
How to reproduce
Insights
I managed to track the problem to the following lines in win32functions.py:
Overriding
GetWindow.restype, which is global, is what causes the problem.Specifications