如何在ctypes python中将char指针作为参数传递 [英] how to pass char pointer as argument in ctypes python
本文介绍了如何在ctypes python中将char指针作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我将下面的c ++代码行转换为python ctypes类型:
Please help me in converting below line of c++ code into 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
是未定义的,但是您需要的常规代码(未调试)是:
myLibrary.resolve
is undefined, but the general code you need (untested) is:
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,其功能为打开
您要呼叫的电话。
This assumes you have a DLL named your.dll
with a function Open
you want to call.
这篇关于如何在ctypes python中将char指针作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文