Obtaining Address Of Custom Data-type In C From Python Using Ctypes
I have a vector struct in C with the following fields, struct vector { unsigned char* data; unsigned long size; unsigned long elemsize; unsigned long capacity; };
Solution 1:
Is there any way in which I can get the address of an output field of some component (say a mirror), which has the type struct vector**, and pass this to, e.g., some function Mirror.set_left_input as the input parameter?
To access the output component of a Mirror given your structures:
>>>m = Mirror()>>>m.output[0]
<__main__.LP_Vector object at 0x00000199607CA0C8>
To pass it to a function by reference:
>>>mirror_set_left_input(byref(m.output[0]),...)
Also, I assume it is necessary to create all fields in the fields of a python structure corresponding to the fields in the C structs - i.e. is it possible to omit some fields from this descriptor or not?
No, you cannot omit fields from your structure definition, or the binary layout of the underlying C structure won't be correct.
Post a Comment for "Obtaining Address Of Custom Data-type In C From Python Using Ctypes"