请帮我将下面的c ++代码转换成ctypes python:
Ret = openFcn(&Handle, "C:\\Config.xml");
下面是每个声明:
typedef uint16_t (* OpenDLLFcnP)(void **, const char *);
OpenDLLFcnP openFcn = NULL;
openFcn = (OpenDLLFcnP) myLibrary.resolve("Open");
void *Handle = NULL;
答案 0 :(得分:5)
myLibrary.resolve
未定义,但您需要的常规代码(未经测试)是:
import ctypes
dll = ctypes.CDLL('your.dll')
Open = dll.Open
Open.argtypes = [ctypes.POINTER(ctypes.c_void_p),ctypes.c_char_p]
Open.restype = ctypes.c_uint16
Handle = ctypes.c_void_p()
result = Open(ctypes.byref(Handle),'c:\\Config.xml')
这假设您有一个名为your.dll
的DLL,其中包含您要调用的函数Open
。