I am working with ctypes using C++ as the backend. Now there is a function like this in C++:
void HandleString(std::string something){
...
}
I am wondering how to call this function from python – there is no ctype (c_char_p wont work obviously) to send a string parameter to this function…
How can I fix this and pass a string from Python to c++ (and changing the parameter to char* something is not and option)
PS Could I create a workaround like this?
- send the python string as c_char_p to C++ function that converts char* to std::string
- return the string or its pointer somehow???!! (how?) to python
- send it from python to HandleString function (but again I feel like I would have to change the parameter to string* here)
Sounds like the simplest approach is to write a thin c++ wrapper around the library for the sole purpose of renegotiating the parameters from python into the more complex c++ classes.
Such an approach would also help remedy future problems of the same kind, without adding any real complexity to neither the python code or the c++ code.