我在 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/