我正在尝试使用 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.
请您检查一下我的代码有什么问题吗?