这里是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);
以及
^{pr2}$经过将近一天的google搜索、阅读晦涩难懂的文档、玩弄代码和内核转储,下面是相应的Python/ctypes代码:
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
希望这对某人有帮助。。。在
目前没有回答
相关问题 更多 >
编程相关推荐