[Numpy-discussion] ctypes, numpy-array

Lars Friedrich lfriedri at imtek.de
Tue Jul 25 05:49:57 CDT 2006


Hello,

I would like to work with some data using python/numpy. The data is
generated with C. To bring the data from C to python, I would like to
use ctype. I am using python 2.4.3 on a windows-System.

To accomplish the described task, I have the following plan. Please tell
me, if this is possible, respectively if there is a better way.

1) In C, I write a .dll, that has a function
int foo(PyObject *arg)

2) In python, I generate a numpy-array with the appropriate size. e.g.
a = zeros((3,3), dtype=int)

3) From python, I call my .dll-function with a as an argument:
windll.mydll.foo(a)

4) In the foo-function in the C-.dll I cast the pointer and access the
data-field.
PyArrayObject *myPtr = (PyArrayObject*) arg;
myPtr->data[0] = 1;
return 0;

However, when I do this, I get an "AccessViolationError writing
0x000000000"

What can I do about it? Thank you for every comment

Lars


-- 
Dipl.-Ing. Lars Friedrich
Optical Measurement Technology
Department of Microsystems Engineering -- IMTEK
University of Freiburg
Georges-Köhler-Allee 102
D-79110 Freiburg
Germany

phone: +49-761-203-7531
fax:   +49-761-203-7537
room:  01 088
email: lfriedri at imtek.de





More information about the Numpy-discussion mailing list