2017-12-18 331 views
1

我有一个包含原始字段(int,uint8,...)和指针的结构。 这些指针通常指向一个不同结构类型的数组,以保持深度嵌套结构。 例如,在C:python ctypes:从指针变量中获取指针类型

struct A 
{ 
int field1; 
int field2; 
struct B *fields3; 
unsigned int countofb; 
} 

struct B 
{ 
    int anotherfield1; 
    int anotherfield2; 
} 

在蟒与ctypes的创建的结构的一个包装和B. 迭代以上结构A的_fields_我到达第三字段field3和我得到LP_struct_B类型的CTYPE变量。

问题是,有没有一种方法,一个函数,ctypes的方法将指针转换为指向类型?

我需要这样的东西

a=A() 
st=pointedtype(a.field3) # or also st = pointedtype2(LP_struct_B) 
#desired output: st = struct_B 

感谢

回答

1

确定。 我已经凭经验找到了答案。 只需使用属性_type_的变量或指针类型

a=A() 
print a.fields3._type_ # struct_B 
tipo=type(a.fields3) # tipo=LP_struct_B 
print tipo._type_ # struct_B