"gianluca" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
hy,
I've a huge problem with ctypes. I've compiled my C library and I'd
like use it in python with ctype. One function need to pass a pointer
to typed ( like this: typedef int value_type). In python I can access
to that funtion but arise an exception  because python don't know my
value_type typedef.

Please I need help, could anybody help me?

Gianluca

Let's see if I understand you correctly. You have a typedef, and a function that is passed a pointer to that typedef. Below is a short Windows DLL, compiled with "cl /LD example.c"

   typedef int value_type;

   __declspec(dllexport) void function(value_type* x)
   {
           *x *= 2;
   }

And here is some python code to call it:

from ctypes import *
value_type = c_int # declares a type "value_type" as a ctypes integer
value=value_type(5)                   # create an instance of value_type
function=cdll.example.function # look up the function and declare return type and arguments
function.restype=None
function.argtypes=[POINTER(value_type)]
function(pointer(value)) # call the function with a pointer to the instance
value
c_long(10)

Hope that helps.
-Mark

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

Reply via email to