6

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

1 回答 1

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

于 2013-09-23T15:55:27.927 回答