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)
std::stringand then callsHandleStringimmediately? In fact, there's an implicit conversion fromconst char*tostd::string, so your workaround function can just use the pointer as the argument expression forHandleString. Don't bother trying to pass thestd::stringback to Python. - Steve Jessop