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);
と
char **ppCharIn;
PythonCallback2FP(&ppCharIn);
cout << ppCharIn[0] << " " << ppCharIn[1];
ほぼ1日のグーグル、あいまいなドキュメントの読み取り、コードの操作、コアダンプの後、対応する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
これが誰かを助けることを願っています...