简体   繁体   English

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

[英]how to pass char pointer as argument in ctypes python

Please help me in converting below line of c++ code into ctypes python: 请帮我将下面的c ++代码转换成ctypes python:

Ret = openFcn(&Handle, "C:\\Config.xml");

below are the declarations of each: 以下是各自的声明:

typedef uint16_t (* OpenDLLFcnP)(void **, const char *);
OpenDLLFcnP openFcn = NULL;
openFcn = (OpenDLLFcnP) myLibrary.resolve("Open");
void *Handle = NULL;

myLibrary.resolve is undefined, but the general code you need (untested) is: 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')

This assumes you have a DLL named your.dll with a function Open you want to call. 这假设您有一个名为your.dll的DLL, your.dll包含您要调用的Open函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM