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

标签 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;

最佳答案

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

关于python - 如何在 ctypes python 中将 char 指针作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18959220/

相关文章:

python - imshow() 子图生成不需要的空白

Python 和 PLY : how to get rid of token 'XXX' , 已定义但未使用

java - 将 int char 转换为 int 而不改变 java 中的值

Python ctypes 和 char**

python - 按特定元素拆分列表以获取列表列表 Python

python - Python 手机的 Socket 编程

mysql - char 与 varchar 用于法语口音(多字节字符)

Java 特殊字符的字符相等

python - 将内存地址从 POINTER(BYTE) 类型转换为十六进制

python - 如何在Python中获取C数组