参考链接
https://www.cnblogs.com/gaowengang/p/7919219.html
https://blog.youkuaiyun.com/m549393829/article/details/80286303
typedef int (*Func)(int*, int*);
# CFUNCTYPE(restype, *argtypes, **kw)
CmpFuncType = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
这里主要解释下:
第一个参数c_int是cFunc函数的返回值int;
第二和第三个参数POINTER(c_int)是cFunc函数的参数int*
# 加载动态链接库文件
ll = cdll.LoadLibrary
lib = ll("lib/libTest.so")
# 生成函数指针
# 假设库中有函数int foo(char*)
foo = lib.foo
# 设置参数格式
foo.argtypes = [c_char_p]
# 设置返回值格式
foo.restype = c_int
ll = cdll.LoadLibrary
lib = ll("lib/libTest.so")
funcA = lib.funcA
funcA.argtypes = [c_char_p]
funcA.restype = c_char_p
res = funcA("test.dat".encode("utf-8")).decode()