问题
I'm using Python 2.7 on Windows 10-32 and Windows 10-64.
I'm writing a python wrapper to a C compiled stdcall (Windows) DLL (= mydll). I have 2 versions of the DLL - 32 and 64 bit.
The 64 version works great using windll.mydll
.
The 32 version works great using the same command for all functions on the DLL, except for variadic printf
-like functions.
When running mydll.myvarfunc("Hello")
I get
ValueError: Procedure probably called with too many arguments (4 bytes in excess)
Is there a way around this that does not involve changing the C code for the variadic functions?
回答1:
On Win64, there is only one ABI so WinDLL and CDLL make no difference. On Win32, variadic functions are always __cdecl
so WinDLL is using the wrong calling convention.
One way to work around this:
import ctypes
stdcall_func = ctypes.WinDLL('mydll').stdcall_func
cdecl_func = ctypes.CDLL('mydll').cdecl_func
来源:https://stackoverflow.com/questions/50386340/windll-ctypes-call-variadic-c-function-from-python-2-7-works-in-win64-but-not-in