2

Closed

ctypes WINFUNCTYPE prototype fails with 'TypeError: WinFunctionType() takes at most 2 arguments (3 given)'

description

The following code from Python 2.7 doc, ctypes tutorial, works fine in CPython, but fails in IPy on line 5, as numbered below:
1 from ctypes import c_int, WINFUNCTYPE, windll
2 from ctypes.wintypes import HWND, LPCSTR, UINT
3 prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
4 paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", "Howdy"), (1, "flags", 0)
5 MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) <== FAILS

MessageBox foreign function can now be called in these ways:

MessageBox()
MessageBox(text="Spam, spam, spam")
MessageBox(flags=2, text="foo bar")
 
Exception message follows:
Traceback (most recent call last):
...
TypeError: WinFunctionType() takes at most 2 arguments (3 given)
 
I need to use several win32 api functions - would rather not have to code these in additional C# dll.
Thanks
Dave
Closed Dec 9 at 8:36 PM by jdhardy
Migrated to GitHub.

comments