30 lines
720 B
Python
30 lines
720 B
Python
![]() |
import ctypes
|
||
|
|
||
|
# 定义内部结构体
|
||
|
class InnerStructLevel2(ctypes.Structure):
|
||
|
_pack_ = 1
|
||
|
_fields_ = [
|
||
|
("inner_field1", ctypes.c_char),
|
||
|
("inner_field2", ctypes.c_double),
|
||
|
("inner_field3", ctypes.c_double),
|
||
|
]
|
||
|
|
||
|
# 定义内部结构体
|
||
|
class InnerStructLevel1(ctypes.Structure):
|
||
|
_pack_ = 1
|
||
|
_fields_ = [
|
||
|
("inner_field1", ctypes.c_int),
|
||
|
("inner_field2", ctypes.c_double),
|
||
|
("inner_level2_field3", InnerStructLevel2)
|
||
|
]
|
||
|
|
||
|
|
||
|
|
||
|
# 定义外部结构体
|
||
|
class OuterStruct(ctypes.Structure):
|
||
|
_pack_ = 1
|
||
|
_fields_ = [
|
||
|
("field1", ctypes.c_int),
|
||
|
("nested", InnerStructLevel1), # 嵌套结构体
|
||
|
("field2", ctypes.c_char * 10),
|
||
|
]
|