Hello,

I am having trouble using ctypes to call a Dll function. In short, the function accepts a pointer to an array of structures....like:

int arrayFiller(
	USHORT sensorID,
	void *pRecord,
	int	recordSize
	);

I have generated a pythonified version of the function by importing the Dll etc. We will call this function "pyArrayFiller"

To call pyArrayFiller, I need to generate the python version of the `void *pRecord` which is a pointer to an array of four structures as defined below:

The c-code for the structure looks like this:

typedef struct tagMyStruct
  {
	double	x;
	double	y;
	double	z;
        double	a;
	double	e;
	double	r;
	double	time;
	USHORT	quality;		
  } MyStruct;

So I constructed a python version of the same structure:

class pyMyStructure(ctypes.Structure):
        _fields_ = [("x", ctypes.c_double),
                    ("y", ctypes.c_double),
                    ("z", ctypes.c_double),
                    ("a", ctypes.c_double),                      
                    ("e", ctypes.c_double),
                    ("r", ctypes.c_double),
                    ("time", ctypes.c_double),
                    ("quality", ctypes.c_double)]

Now, I would like to:

i.) create an array of 4 pyMyStruct()`s
ii.) generate a pointer to this array to pass to the 'pyArrayFiller' function.

Any tips? If this is a terrible/insufficient explanation, I can try again.

Thanks!

I think you create an array like this

arr = (pyMyStructure * 4)()

but I'm a beginner in ctypes. Perhaps you can pass ctypes.pointer(arr) to your function.

Edited 5 Years Ago by Gribouillis: n/a

Hi!

Yeah Gribouillis - the solution I ended up with was along those lines:

recordPointerType = structures.pyDoubleMeasuresRecord * 4 
            
record = recordPointerType() 

recordPointer = ctypes.pointer(record)

I liked yours better, so that's what ended up in the code. Thanks Gribouillis!

This question has already been answered. Start a new discussion instead.