python - 选择 ctypes dll 加载机制
问题描述
我正在研究一些可以使用 ctypes 访问某些 dll 功能的代码。库加载是通过以下方式完成的:
U2_C_INTERFACE = ctypes.cdll.LoadLibrary("mydllname")
这适用于原始开发人员 Windows 10 机器(和其他机器)。但是在我自己的机器上调用库方法时出现了这个错误:
Procedure called with not enough arguments (24 bytes missing) or wrong calling convention
谷歌搜索后,我可以修复它,将 dll 加载方法更改为:
U2_C_INTERFACE = ctypes.windll.LoadLibrary("mydllname")
这适用于我自己的 Windows 10 机器(和其他机器)。但它在原来的 Windows 10 机器上不起作用,我们在调用库方法时遇到了另一个错误:
Procedure probably called with too many arguments (24 bytes in excess)
有没有办法以编程方式知道何时使用cdll.LoadLibrary
以及何时使用windll.LoadLibrary
?
这是麻烦的代码,调用o_session
是抛出注释异常
if U2_C_INTERFACE is None:
# U2_C_INTERFACE = ctypes.cdll.LoadLibrary("uvic32")
U2_C_INTERFACE = ctypes.windll.LoadLibrary("uvic32")
subkey = c_char_p(bytes(0))
status = c_long(0)
host_l = bytes(servidor_uv, servidor_universe.devolver_sistema_codificacion())
user_l = bytes(usuario_uv, servidor_universe.devolver_sistema_codificacion())
pass_l = bytes(password_uv, servidor_universe.devolver_sistema_codificacion())
acc_l = bytes(cuenta_uv, servidor_universe.devolver_sistema_codificacion())
# Gestión de apertura de sesión
o_session = U2_C_INTERFACE.ic_universe_session
o_session.argtypes = (
c_char_p, c_char_p, c_char_p,
c_char_p, c_char_p, _ctypes.POINTER(c_long))
res = o_session(
c_char_p(host_l), c_char_p(user_l), c_char_p(pass_l),
c_char_p(acc_l), subkey, _ctypes.byref(status))
我们使用的 Python 版本是 3.4.0(32 位)
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32
我的 ctypes 版本是 1.1.0。
解决方案
推荐阅读
- python - 合并多行输出?
- javascript - 如何在 Unobtrusive Javascript onclick 分配中使用变量?
- react-leaflet - React Leaflet V3 自定义控件
- reactjs - 使用上下文不会更新反应状态?
- c# - 在 C# .NET 中,Directory.GetDirectories 或 Directory.GetFiles 不能从哪些目录获取目录或文件,为什么?
- xamarin - RestSharp GET 错误请求
- flutter - 在 Onboard Pages 上进行 Flutter 应用程序初始化?
- php - 在 meta property="og:url" 中未显示完整的 url
- java - 如何使用 org.json 写入 json
- c - 有没有办法在 C-API 中抑制 TensorFlow 日志记录