ctypes的指针(c_void_p)在回调函数 [英] ctypes POINTER(c_void_p) in a callback function
本文介绍了ctypes的指针(c_void_p)在回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前面临的一个问题ctypes的。我有一个C函数foo这样:
I am currently facing a problem with ctypes. I have a C function foo such that:
void** foo(int);
我要定义foo的函数的回调函数。所以:
I have to define a callback function for the foo function. So:
FOO_FUNC = CFUNCTYPE(POINTER(c_void_p), c_int)
foo_c = lib.foo
foo.argtypes = [c_int]
foo.restype = POINTER(c_void_p)
不幸的是,当调用一个函数采取这种回调函数作为参数,它给人的错误:
类型错误:无效结果类型回调函数
我看不到这个问题...谁能帮助我?
谢谢
I can't see the problem... Can anyone help me? Thanks
推荐答案
使用 c_void_p
而不是指针(c_void_p)
。我认为,应该修复它。另外请注意,您不能使用复合类型回调返回类型: Issue5710
Use c_void_p
instead of POINTER(c_void_p)
. I think that should fix it. Also note that you cannot use composite types as callback return types: Issue5710
这篇关于ctypes的指针(c_void_p)在回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文