Ok, then you only need a few small updates.
First, declaring your argument is disabled, but that probably doesn't matter. A pointer is a pointer as regards the python-c value translation mechanism. The most accurate would be POINTER(POINTER(myStruct))
, but to simplify the task, just use:
library.func.argtypes = [c_void_p]
Next, you donβt have to worry about instantiating myStruct
to indicate your argument; you only need the correct pointer and a pointer to it. func
will highlight the actual instances of myStruct
. So start with:
Foo = ctypes.POINTER(myStruct)()
Now we can call it. We have myStruct*
, but we will give it a pointer so func
can change it. We do not need to create a whole other pointer object, so we will use a lighter byref
:
Bar = library.func(byref(Foo))
Now you can iterate through Foo[i]
.
for i in range(Bar): print("id = %u, name = %s" % (Foo[i].id, Foo[i].name))
source share