I'm trying to expose a c++ function taking a const wchar_t* as a parameter in python. It seems to me that const wchar_t* is not a supported input type that is automatically exposed as a python string and then converted automatically like an ordinary const char*.
Is it possible to add some kind of input type converter that gets this right automatically? I know I can add trampoline functions and do the unicode conversion myself but it would be much more convenient to get this to behave right automatically.
My boost version is 1.52 and I'm working with python 2.7 on 64bit windows.
Here is example code for a trivial c++ sequence showing the issue:
#include <boost/python.hpp>
#include <iostream>
using namespace boost::python;
void testWcharParam(const wchar_t* str) {
std::wcout << str << std::endl;
}
void testCharParam(const char* str) {
std::wcout << str << std::endl;
}
BOOST_PYTHON_MODULE(test)
{
def("testWcharParam", testWcharParam);
def("testCharParam", testCharParam);
}
When importing and running this in python I get the following result:
>>> import test
>>> test.testCharParam('test')
test
>>> test.testWcharParam('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
test.testWcharParam(str)
did not match C++ signature:
testWcharParam(wchar_t const * __ptr64)
>>>
For some reason the approach for strings here http://www.boost.org/doc/libs/1_52_0/libs/python/doc/v2/faq.html#custom_string doesn't work for raw wchar_t*.
EDIT: Added missing includes and platform information.
EDIT: Added note on the example in the boost documentation