windll ctypes從python 2.7調用variadic c函數在win64中工作但在win32中不工作

[英]windll ctypes call variadic c function from python 2.7 works in win64 but not in win32

I'm using Python 2.7 on Windows 10-32 and Windows 10-64.

我在Windows 10-32和Windows 10-64上使用Python 2.7。

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.

我正在為C編譯的stdcall(Windows)DLL(= mydll)編寫一個python包裝器。我有兩個版本的DLL - 32和64位。 64版本使用windll.mydll很有效。對於DLL上的所有函數,32版本使用相同的命令很有效,除了類似於variadic printf的函數。

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



粤ICP备14056181号  © 2014-2021