python - 来自python 2.7的windll ctypes调用可变参数c函数在win64中有效,但在win32中无效
问题描述
我在 Windows 10-32 和 Windows 10-64 上使用 Python 2.7。
我正在为 C 编译的 stdcall (Windows) DLL (= mydll) 编写一个 python 包装器。我有 2 个版本的 DLL - 32 位和 64 位。64 版本使用windll.mydll
. 32 版本对 DLL 上的所有函数使用相同的命令效果很好,除了类似可变参数printf
的函数。
跑步时mydll.myvarfunc("Hello")
我明白了
ValueError: Procedure probably called with too many arguments (4 bytes in excess)
有没有一种不涉及更改可变参数函数的 C 代码的方法?
解决方案
在 Win64 上,只有一个 ABI,因此 WinDLL 和 CDLL 没有区别。在 Win32 上,可变参数函数总是__cdecl
这样 WinDLL 使用错误的调用约定。
解决此问题的一种方法:
import ctypes
stdcall_func = ctypes.WinDLL('mydll').stdcall_func
cdecl_func = ctypes.CDLL('mydll').cdecl_func
推荐阅读
- vb.net - 如何根据另一个 datetimepicker VB.NET (Visual Studio) 自动设置 datetimepicker
- sql - 具有变体数据类型的 SQL 数据库设计
- android - Oppo Realme 1 未在 android studio 3 中检测到用于调试
- clojurescript - 将宏应用于向量
- javascript - 我正在尝试找到持续时间流量的中点(基于与出发时间相关的流量)
- spring-boot - 我们需要如何在 Spring Boot 控制器中检索自定义标头?
- elixir - 带有多个“或”子句的 Ecto Repo.get_by
- spring-boot - Spring Boot 2 setRedirectPort 未重定向到 8443
- flutter - ScrollController 未附加到任何滚动视图
- sql - 查询以根据今天的日期返回具有连续日期的行