Skip to content
Advertisement

float pointer in ctypes python and pass structure pointer

I’m trying to pass a structure pointer to the API wrapper, Where the struct is containing float pointer member. I’m not sure that how we can pass float pointer value to the structure.

/Structure/

JavaScript

/wrapper/

JavaScript

Advertisement

Answer

You can either create a c_float instance and initialize with a pointer to that instance, or create a c_float array and pass it, which in ctypes imitates a decay to a pointer to its first element.

Note that ctypes.pointer() creates pointers to existing instances of ctypes objects while ctypes.POINTER() creates pointer types.

test.c – for testing

JavaScript

test.py

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement