python如何映射 包含union的结构体啊?
求解决方案啊!
比如结构体:
struct a{
int arg0;
union{
int b;int c;int d;
}
}
用ctypes该如何抽象出来?
怎么使用呢?
[解决办法]
不认真看,明明有个范例...
_anonymous_
An optional sequence that lists the names of unnamed (anonymous) fields. _anonymous_ must be already defined when _fields_ is assigned, otherwise it will have no effect.
The fields listed in this variable must be structure or union type fields. ctypes will create descriptors in the structure type that allows to access the nested fields directly, without the need to create the structure or union field.
Here is an example type (Windows):
class _U(Union):
_fields_ = [("lptdesc", POINTER(TYPEDESC)),
("lpadesc", POINTER(ARRAYDESC)),
("hreftype", HREFTYPE)]
class TYPEDESC(Structure):
_anonymous_ = ("u",)
_fields_ = [("u", _U),
("vt", VARTYPE)]