I'm working with a closed source shared library with example code in C++ like so:
// Header
#define MAX_PARAM_NAME 10
int foo(..., char **ParNameList, ...);
// Main
char *ParNameList = (char *)NULL;
ret = foo(..., &ParNameList,...);
par = (char (*)[MAX_PARAM_NAME])ParNameList;
How should it be handled in ctypes?
The problematic part is that in function declaration foo(..., char **ParNameList, ...); a char ** is expected, but a reference to char * is actually given in the function call.
So far I have:
from ctypes import *
so = cdll.LoadLibrary(...)
so.foo.argtypes = [
...
POINTER(POINTER(c_char)), # ParNameList
...
]
so.foo.restype = c_int
#...
ParNameList = POINTER(c_char)()
so.foo(..., ParNameList ,...)
which gives me a garbage string, where I see the required output is interleaved with random changing RAM bits.
But how does (char (*)[MAX_PARAM_NAME]) cast work in ctypes?
If there is a more straight forward way for the whole thing, I'd appreciate to hear it.
char **as per function definition andchar *in C-Code. In the C-Example the array of char pointers needs to be decomposed after the function call.