I have an C api that i\'m interfacing with the python ctypes package. Everything works well, except this little tidbit.
To register functions as callbacks to some n
You can't, so far as I know, call a bound method because it is missing the self parameter. I solve this problem using a closure, like this:
CALLBACK = ctypes.CFUNCTYPE(None, ctypes.POINTER(Notification))
class MyClass(object):
def getCallbackFunc(self):
def func(Notification):
self.doSomething(Notification)
return CALLBACK(func)
def doRegister(self):
myLib.RegisterNofityCallback(45454, 0, self.getCallbackFunc())