[英]DLL use in Python 2.7 with ctypes
I have a problem about using DLL file. 我在使用DLL文件时遇到问题。 The code I used is below.
我使用的代码如下。 In handbook of DLL it writes the signiture of function.
在DLL手册中,它写了函数的签名。 I'm using Python 2.7
我正在使用Python 2.7
from ctypes import *
mtrs= windll.LoadLibrary("mtrs.dll")
mtrs.sw_Open("SystemWorks", 0, c_ulong( 0x100 | 0x10000), None, None)
0
In handbook of DLL it writes the signature of function. 在DLL手册中,它写入功能的签名。
DLLINOUT BOOL WINAPI sw_Open(LPCSTR DeviceName, ULONG DeviceNumber, ULONG OpenFlags, void * Arg1, void * Arg2 );
Function returns false if device is not opened. 如果未打开设备,函数将返回false。
Is there any error in parameters? 参数是否有错误?
如果使用的是Python 3x,则应使用b"SystemWorks"
因为第一个参数的类型为LPCSTR
。
#!/usr/bin/env python3
from ctypes import *
mtrs= windll.LoadLibrary("mtrs.dll")
mtrs.sw_Open.argtypes = [c_char_p, c_ulong, c_ulong, c_void_p, c_void_p]
mtrs.sw_Open.restype = c_bool
mtrs.sw_Open(b"SystemWorks", c_ulong(0), c_ulong( 0x100 | 0x10000), None, None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.