在 ctypes 读取 so/dll 时只知道存在这个函数,但是并不知到函数的形参类型和返回值的类型。
两个属性 restype 和 argtypes 赋值了,它们分别对应返回类型和参数类型:
from ctypes import *
dlltest = windll.LoadLibrary("D:\dll\DllDemo.dll")
dlltest.display.argtypes = [c_char_p,c_double] # 定义传入dll的数据参数类型,第一个为char*类型,第二个为double类型
dlltest.display.restype = c_char_p # 定义dll返回的数据参数类型,不定义默认为int
pchar = dlltest.display(5)
p = pchar.decode('gbk') #接收的char* 数据类型为bytes ,需要重新编码