How Do I Wrap This C Function, With Multiple Arguments, With Ctypes?
I have the function prototype here: extern 'C' void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to write some python to access this
Solution 1:
To make an array with, say, n
doubles:
arr7 = ctypes.c_double * `n`
x = arr7()
and pass x
to your function where it wants a double*
. Or if you need to initialize x
as you make it:
x = arr7(i*0.1 for i in xrange(7))
and the like. You can loop over x
, index it, and so on.
Solution 2:
I haven't looked at ctypes too much, but try using a numpy array of the right type. If that doesn't just automatically work, they also have a ctypes attribute that should contain a pointer to the data.
Post a Comment for "How Do I Wrap This C Function, With Multiple Arguments, With Ctypes?"