views:

159

answers:

2

Hi everyone! 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 function that is in a DLL. I have loaded the DLL, but each of the double* is actually pointing to a variable number of doubles (an array), and I'm having trouble getting it to function properly.

Thanks all!

+1  A: 

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.

kwatford
+1  A: 

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.

Alex Martelli
Awesome! Thanks!
trayres
You're welcome; if this answer proves to be the solution to your problem, remember to accept it (use the checkmark icon under the number giving up/down vote count for the answer), that's fundamental SO etiquette.
Alex Martelli
Ah, thank you again!
trayres