我想在Linux中编写一个包装到本地库。问题是这样的:python ctypes发送指针结构作为参数到本地库
定义在C:
int mymethod(mystruct* ptr)
:
_lib.mymethod.argtypes = (ctypes.POINTER(mystruct),)
_lib.mymethod.restype = ctypes.c_int
s = mystruct()
_lib.mymethod(ctypes.byref(s))
加注:预计LP_mystruct实例,而不是指向MYSTRUCT代替LP_mystruct
错误
_lib.mymethod(ctypes.pointer(s))
引发预期LP_mystruct实例。如何将结构作为指针传递给本地方法?
谢谢。
METE
谢谢!我用你说的第二种方法,它没有问题。 – mete 2012-02-03 16:14:24
这里有类似的东西 - https://codexample.org/questions/238108/python-ctypes-sending-pointer-to-structure-as-parameter-to-native-library.c – 2017-09-07 07:50:42
这是ctypes中更高级别的POINTER类型? – 2017-09-07 10:07:06