I have a SWIG C++ function that expects a function pointer (WNDPROC), and want to give it a Python function that has been wrapped by ctypes.WINFUNCTYPE.
It seems to me that this should be compatible, but SWIG's type checking throws an exception because it doesn't know that the ctypes.WINFUNCTYPE type is acctually a WNDPROC.
What can I do to pass my callback to SWIG so that it understands it?
I don't have a windows machine to really check this, but I think you need to create a typemap to tell swig how to convert the PyObject wrapper to a WNDPROC:
// assuming the wrapped object has an attribute "pointer" which contains
// the numerical address of the WNDPROC
%typemap(in) WNDPROC {
PyObject * addrobj = PyObject_GetAttrString($input, "pointer");
void * ptr = PyLong_AsVoidPt(addrobj);
$1 = (WNDPROC)ptr;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With