I've got a dll which defines a structure. Within this structure is a field that has the type CRITICAL_SECTION, as included from windows.h. How can I define a ctypes structure in python to reference this type? Since CRITICAL_SECTION is itself a struct (with references to other structs in its own definition), do I really have to define the python ctype equivalents such that I have a python CRITICAL_SECTION that I can reference? Is there a better way?
Example C program:
...
typedef struct some_struct {
...
CRITICAL_SECTION field1;
} SOME_STRUCT;
...
Example Python program:
...
class SOME_STRUCT(Structure):
_fields_ = [... ('field1', CRITICAL_SECTION)]
How do I make ctypes recognize what CRITICAL_SECTION is without going down the rabbit hole of defining everything down to primitive types that ctypes recognizes?
c_ubyte * xwhere x issizeof(CRITICAL_SECTION)might be sufficient. As long as your final structure is the right size, you can just treat it as an opaque array of bytes. - Mark Tolonensizeof(CRITICAL_SECTION)anyway :D - Antti Haapala