C++ 如何通过ctypes从dll回调向python传递字符**,并将其返回给dll?

C++ 如何通过ctypes从dll回调向python传递字符**,并将其返回给dll?,c++,python,c,ctypes,C++,Python,C,Ctypes,以下是C/C++客户端调用: char **ppCharOut; char *pHello = "hello"; char *pWorld = "world"; ppCharOut = new char*[2]; ppCharOut[0] = pHello; ppCharOut[1] = pWorld; PythonCallback1FP(reinterpret_cast<int>(&ppCharOut), 2); 及 希望这对某人有所帮助……对不起,这是回答还是澄清?这似

以下是C/C++客户端调用:

char **ppCharOut;
char *pHello = "hello";
char *pWorld = "world";
ppCharOut = new char*[2];
ppCharOut[0] = pHello;
ppCharOut[1] = pWorld;
PythonCallback1FP(reinterpret_cast<int>(&ppCharOut), 2);


希望这对某人有所帮助……

对不起,这是回答还是澄清?这似乎不是你问题的答案。这是答案-我花了6-8个小时试图找出它,然后把它贴在这里给其他人…
POINTER(POINTER(POINTER(c_char\u p))
is
char***
yes as is&ppChar,尽管我想你可以将它简化为一个char**来将字符串数组传递给python。不过,您仍然需要使用&ppChar从python获取字符串数组。
char **ppCharIn;
PythonCallback2FP(&ppCharIn);
cout << ppCharIn[0] << " " << ppCharIn[1];
def PythonCallBack1FP(arg1, arg2):
    from ctypes import POINTER, cast, c_char_p
    ppChar = cast(arg1, POINTER(POINTER(c_char_p))).contents
    for i in xrange(arg2):
        print ppChar[i]
def PythonCallback2FP(addressOfCharPP):
    from ctypes import POINTER, cast, c_char_p, pointer
    ArrayType = c_char_p * 2
    arrayOfCharPs = ArrayType()
    arrayOfCharPs[0] = "HELLO"
    arrayOfCharPs[1] = "BACK"
    charPP = pointer(arrayOfCharPs)
    ptr = cast(addressOfCharPP, POINTER(POINTER(ArrayType))
    ptr[0] = charPP