Python 3.5.1 (AMD64) ctypes.ArgumentError : argument 1: <class 'OverflowError' >: int too long to convert

标签 python windows-10 ctypes

我在 WIN32 上使用 Python 3.5.1 (AMD64)

我在 Windows 10 中运行代码 有任何关于如何修复错误的建议吗?

ctypes.ArgumentError: argument 1: <class 'OverflowError'>: int too long to convert

最佳答案

对我来说,有两种方法可以防止这种情况发生:

假设我们有这个函数:

USB_GetDeviceInterfaceList(QWORD DeviceId, BYTE *pInterfaceList, DWORD *pdwInterfaceAmount)

这会起作用:

通用共享代码:

from ctypes import *
slibc = 'lib\\usb.dll'
libc = CDLL(slibc)

interface_list = (c_byte * 128)()
interface_amount = c_int()

第一种方法,定义 argtypes:

ctypes.libc.USB_GetDeviceInterfaceList.argtypes = [c_int64, POINTER(c_byte * 128), POINTER(c_int)]
libc.USB_GetDeviceInterfaceList(2425014470954602011, byref(interface_list), byref(interface_amount))

第二种方法,使用类型转换:

libc.USB_GetDeviceInterfaceList(c_int64(2425014470954602011), byref(interface_list), byref(interface_amount))

关于Python 3.5.1 (AMD64) ctypes.ArgumentError : argument 1: <class 'OverflowError' >: int too long to convert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163105/

相关文章:

python - Tkinter 实时图形 Canvas 停止更新,直到鼠标移动

python - 加快 Pandas 应用或使用 map

python - neo4j:返回最长匹配补丁上的所有节点

Python 已停止工作

c# - 无法激活 Windows 应用商店应用程序(Visual Studio 2015,Windows 10 版本 1511)

windows-10 - 在 JDK9 中禁用 BufferedImage 的自动缩放

Python ctypes 无法在结构中传递内存数组

python - 为什么 '() is ()'和 '[] is []'返回False时 '{} is {}'返回True?

python - 加载和访问多个 ctype 实例

c++ - 从 Python 调用定制的 C++ dll