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")

運行mydll.myvarfunc(“Hello”)時

I get ValueError: Procedure probably called with too many arguments (4 bytes in excess)

我得到ValueError:過程可能被調用太多參數(超過4個字節)

Is there a way around this that does not involve changing the C code for the variadic functions?

有沒有辦法繞過這個不涉及更改可變參數函數的C代碼?

1 个解决方案

#1


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.

在Win64上,只有一個ABI,因此WinDLL和CDLL沒有區別。在Win32上,可變參數函數總是__cdecl,因此WinDLL使用錯誤的調用約定。

One way to work around this:

解決此問題的一種方法:

import ctypes
stdcall_func = ctypes.WinDLL('mydll').stdcall_func
cdecl_func = ctypes.CDLL('mydll').cdecl_func

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/05/17/3e4480d76eaa377a4114dc84350f57.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com