请帮助我将下面的 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;
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