python调用dll相对而言比较方便,写个脚本调试轻松工作,快乐生活。
python脚本
from ctypes import * import time # 脚本挂起 input() # load dll __stdcall 方式 dll = windll.LoadLibrary('IDPSOLID510Lib.dll'); print("dll handle=",dll); #获取版本号 p_version = create_string_buffer(512); ret = dll.get_version(p_version); s = string_at(p_version,-1).decode('gbk'); print("ret=",ret," version= ",s); # 调用结果例子 # ret= 0 version= model: CardScriptComplier | version: v1.0.1.20180214 # 枚举设备 ret = dll.EnumDevice(p_version); # 连接设备 ret = dll.ConnectDevice(p_version); print(" start ==") for i in range(15): print("--------count index: %d --------" % (i+1)) # 进卡 ret = dll.MoveCard_In(p_version); ret = dll.MoveCard_RF(p_version); # 模拟洗卡过程 time.sleep(6.5) # 出卡 # ret = dll.MoveCard_Out(p_version); ret = dll.MoveCard_OutBack(p_version); print("end ==") # 关闭设备 ret = dll.DisConnectDevice(p_version); # GetDeviceInfo # GetDeviceStatus # # MoveCard_OutBack print("ret=",ret);
dll代码--def模块定义文件
; IDPSOLID510Lib.def : 声明 DLL 的模块参数。 LIBRARY "IDPSOLID510Lib" EXPORTS ; 此处可以是显式导出 get_version EnumDevice ConnectDevice DisConnectDevice GetDeviceInfo GetDeviceStatus MoveCard_In MoveCard_RF MoveCard_Out MoveCard_OutBack
dll代码
EXTERN_C int WINAPI GetDeviceInfo() { int ret = 0; SMART_PRINTER_INFO DevInfo; // get info ret = smartCommon.GetDeviceInfo2(&DevInfo, szDev, 1); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "getdeviceinfo fail, errcode=%x", ret); return -1; } return ret; } EXTERN_C int WINAPI GetDeviceStatus(char*) { int ret = 0; long long status = 0; ret = smartCommon.GetStatus(&status); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "getdevicestatus fail, errcode=%x", ret); return -1; } return ret; } EXTERN_C int WINAPI MoveCard_In(char* ErrMsg) { int ret = 0; ret = smartCommon.CardIn(); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "movecard_in fail, errcode=%x", ret); return -1; } return ret; } EXTERN_C int WINAPI MoveCard_RF(char*) { int ret = 0; ret = smartCommon.Move(CARDPOS_RF); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "movecard_rf fail, errcode=%x", ret); return -1; } return ret; } EXTERN_C int WINAPI MoveCard_Out(char*) { int ret = 0; ret = smartCommon.CardOut(); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "movecard_out fail, errcode=%x", ret); return -1; } return ret; } EXTERN_C int WINAPI MoveCard_OutBack(char*) { int ret = 0; ret = smartCommon.CardOutBack(); if (ret != 0) { ErrorLog(gobal_logger, __FILE__, __LINE__, "cardoutback fail, errcode=%x", ret); return -1; } return ret; }
vs2015调试配置
命令行执行 python testdll.py
启动vc调试,断点就到了。
参考: https://blog.csdn.net/lacoucou/article/details/80066637