CTypes and Incomplete Types
Some days ago I was writing a DLL’s wrapper in ctypes and I came across of this typedef in the header file:
typedef struct _FILEHandle *FILEHandle;
To translate this definition into ctypes is pretty straight-forward (if you already know the solution :-) ).
First of all, _FILEHandle
is a forward declaration and the definition of the struct’s fields are not exposed in the header file. So this is obviously an Incomplete Type and we can declare a ctype’s like this:
class _FILEHandle(Structure):
pass
Finally, FILEHandle
is pointer to an instance of _FILEHandle
so it will be declared like that:
FILEHandle = POINTER(_FILEHandle)