如何在ctypes python中将char指针作为参数传递

时间:2013-09-23 12:27:55

标签: python char ctypes

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

1 个答案:

答案 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