I'd like to read an array of structs defined in a C library using ctypes and python.
The C struct is simply
struct particle {
double x;
double y;
}
I have a function that returns a pointer to an array of structs:
struct particle* getParticles();
In python I define
class Particle(Structure):
_field_ = [("x", c_double),("y", c_double)]
Then I'm trying to parse the returned pointer from python, but seem to be doing something wrong:
getp = libparticles.getParticles
getp.restype = POINTER(Particle)
particles = getp()
particles is of type LP_Particle, which seems to make sense. But the values (e.g. particles[0].x) are garbage.
libparticles? It helps to post a fully functional example that illustrates the problem. My guess is the function uses "C" calling convention and you've initialized as "stdcall" or vice versa.