我在 C 中有一個庫,它有一個物件IedConnection來處理與遠程設備的連接。
IedConnection con = IedConnection_create();
IedConnection_connect(con, &error, hostname, tcpPort);
IedConnection_destroy(con);
我了解如何傳遞和回傳ctype物件c_int,但如何IedConnection con在 python 中使用ctypes?
uj5u.com熱心網友回復:
IedConnection是指向結構 ( typedef struct sIedConnection * IedConnection)的指標。所有指向結構的指標都應該具有相同的表示形式,因此您可以只使用指向任何結構的指標,而無需定義其內容,除非您想取消參考它或進行指標算術。因此這應該有效:
from ctypes import *
class SIedConnection(Structure):
pass
IedConnection = POINTER(SIedConnection)
現在您可以像往常一樣IedConnection用作回傳型別和引數型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335214.html
