我有一个 C 语言库,其中有一个对象 IedConnection
,用于处理与远程设备的连接。
IedConnection con = IedConnection_create();
IedConnection_connect(con, &error, hostname, tcpPort);
IedConnection_destroy(con);
我了解如何传递和返回 ctype
对象,例如 c_int
,但是如何使用 在 python 中声明
?IedConnection con
对象>ctypes
最佳答案
IedConnection
是一个指向结构的指针(typedef struct sIedConnection * IedConnection
)。所有指向结构的指针都应该具有相同的表示形式,因此您可以只使用指向任何结构的指针,并且不需要定义其内容,除非您想取消引用它或进行指针算术。因此这应该有效:
from ctypes import *
class SIedConnection(Structure):
pass
IedConnection = POINTER(SIedConnection)
现在您可以使用 IedConnection
作为 return type并在 argument types像往常一样。
关于python - 使用 ctypes 通过引用接收传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69700568/