我正在尝试使用Python中的ctypes库访问Digital Persona DLL函数。
我写了下面的测试代码:
import ctypes
dpfpddDll = ctypes.CDLL ("dpfpdd.dll")
# Library initialization.
dpfpdd_init = dpfpddDll.dpfpdd_init
dpfpdd_init.restype = ctypes.c_int
result = dpfpdd_init()
# Opening the device
device_name = "EB31330E-43BD-424F-B7FB-D454CCF90155"
dpfpdd_open = dpfpddDll.dpfpdd_open
dpfpdd_open.restype = ctypes.c_int
dpfpdd_open.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
p1 = ctypes.c_char_p(device_name.encode("ascii")) # or device_name.encode("utf-8")
p2 = ctypes.c_void_p()
result = dpfpdd_open(p1,p2)似乎库初始化工作正常,因为我得到的结果等于0,这意味着成功,但对于第二个函数调用,我得到的是python异常:
Exception has occurred: OSError
exception: access violation writing 0x0000000000000000第二个函数的文档:
typedef void* DPFPDD_DEV
int DPAPICALL dpfpdd_open( char * dev_name,
DPFPDD_DEV * pdev )Opens a fingerprint reader in exclusive mode.
If you or another process have already opened the reader, you cannot open it again.
Parameters
dev_name Name of the reader, as acquired from dpfpdd_query_devices().
pdev [in] Pointer to empty handle (per DPFPDD_DEV); [out] Pointer to reader handle.
Returns
DPFPDD_SUCCESS: A valid reader handle is in the ppdev;
DPFPDD_E_FAILURE: Unexpected failure;
DPFPDD_E_INVALID_PARAMETER: No reader with this name found;
DPFPDD_E_DEVICE_BUSY: Reader is already opened by the same or another process;
DPFPDD_E_DEVICE_FAILURE: Failed to open the reader.你能检查一下我的代码有什么问题吗?
发布于 2020-07-28 20:14:36
你需要阅读声明
typedef void* DPFPDD_DEV
int DPAPICALL dpfpdd_open(char *dev_name, DPFPDD_DEV *pdev)更接近一些:-)
第二个参数实际上是void**类型(因为DPFPDD_DEV扩展为void*)。
尝试
# ...
p2 = ctypes.c_void_p()
result = dpfpdd_open(p1, ctypes.pointer(p2))-软件开发工具包将在内部为设备结构分配内存,并将其地址分配给您的p2指针。
这相当于C代码
DPFPDD_DEV dev;
dpfpdd_open(..., &dev);https://stackoverflow.com/questions/63133585
复制相似问题