我想在python开发的软件中增加指纹识别的功能,买了一款现成的指纹仪,厂家提供的dll是c开发的,我在用python调用dll方法时总是不对,用方法1和方法2返回的句柄都跟客户给的示例程序返回的长度不一样,客户程序始终为9位正数,在python中得到的一直为10位长度,且有时为负数。不知大家有知道如何正确获取设备句柄的方法吗?
c函数定义如下:打开设备函数
int WINAPI OpenDevice(HANDLE* pHandle, int nDeviceType,int iCom,int iBaud,int nPackageSize/=2/,int iDevNum/=0/)
关闭设备函数
int WINAPI CloseDevice(HANDLE hHandle)
python代码如下:
import ctypes
dll = ctypes.CDLL('./zhiwen.dll')
handle = 0
def openDev(_handle):
#方法1:
type_p_int = ctypes.POINTER(ctypes.c_int)
v = ctypes.c_int(handle)
p_int = type_p_int(v)
ret = dll.OpenDevice(p_int,2,0,0,2,0)
#方法2:
h = ctypes.c_int(_handle)
ret = dll.OpenDevice(ctypes.byref(h),2,0,0,2,0)
openDev(handle)