SWIG 的 Python ctypes 回调函数
我有一个 SWIG C++ 函数,它需要一个函数指针 (WNDPROC),并且想给它一个由 ctypes.WINFUNCTYPE 包装的 Python 函数。
在我看来,这应该是兼容的,但 SWIG 的类型检查会引发异常,因为它不知道 ctypes.WINFUNCTYPE 类型实际上是 WNDPROC。
我该怎么做才能将我的回调传递给 SWIG 以便它理解?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有 Windows 机器来真正检查这一点,但我认为您需要创建一个类型映射来告诉 swig 如何将 PyObject 包装器转换为 WNDPROC:
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: