【发布时间】:2019-02-21 21:55:13
【问题描述】:
我有一个带有函数的 DLL
EXPORT long Util_funct( char *intext, char *outtext, int *outlen )
看起来它需要 char *intext、char *outtext、int *outlen。 我试图在 python 中定义不同的数据类型,所以我可以传递一个参数,但到目前为止没有成功。
from ctypes import *
string1 = "testrr"
#b_string1 = string1.encode('utf-8')
dll = WinDLL('util.dll')
funct = dll.Util_funct
funct.argtypes = [c_wchar_p,c_char_p, POINTER(c_int)]
funct.restype = c_char_p
p = c_int()
buf = create_string_buffer(1024)
retval = funct(string1, buf, byref(p))
print(retval)
输出为无,但我看到p 发生了一些变化。
你能帮我为函数定义正确的数据类型吗?
【问题讨论】:
-
返回类型(
restype)是c_long,而不是c_char_p。 -
如果您的函数需要一个可变缓冲区,您可能还需要使用
string1 = create_string_buffer('testrr')而不是string1 = 'testrr'。