En Tue, 28 Jul 2009 00:06:06 -0300, jammy <huzaig...@cn.panasonic.com> escribió:

I an just starting to use the ctypes module.
Now I want to expentd C in python.
In the function of C, I want to get the output struct parameter which is chaged in the function.

You're mixing a C extension with a ctypes call - why is that?
ctypes is mainly used when you *don't* want to actually write a C extension - if you actually write one, you don't need ctypes at all.

----------- 1.Header file of C(information.h)-----------
typedef struct {
 char  name[20];
 int   height;
 int   weight;
} Infor;
int getInfor( char* name, int height, int weight, Infor* infor);

----------- 5.test file of Python(test.py)-----------
    Extest.getInfor(name, height, weight, byref(infor))

All arguments for a function intended to be called from Python must be PyObject*; byref is used to call a ctypes-wrapped function, not a function from an extension module. (You're lucky you didn't crash the interpreter process)

Either use ctypes to directly call the getInfor function in information.c (and drop the extension module), or write a complete wrapper in the extension module and forget ctypes. Don't mix both ways.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to