【发布时间】:2013-01-29 18:25:10
【问题描述】:
我的 C 代码返回一个指向该结构的指针,这就是我在 python 中定义它的方式
class CONTEXT(ctypes.Structure):
_fields_ = [
("sockfd", ctypes.c_int),
("eidSeq", ctypes.c_longlong)
]
# API
# connect
PY_connect=NativeDll.gf_connect
# connect input and output parameter declaration
PY_connect.argtype = [
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.POINTER(ctypes.c_int)
]
PY_connect.restype = [
ctypes.POINTER(CONTEXT)
]
但我收到restype 的以下错误
TypeError: restype must be a type, a callable, or None
【问题讨论】:
-
这里纯属猜测,但我建议 restype 应该只是一个普通类型,而不是您当前拥有的类型列表。