En Mon, 28 Apr 2008 18:55:15 -0300, Diez B. Roggisch <[EMAIL PROTECTED]>
escribió:
VernM schrieb:
I am using ctypes to wrap a set of functions in a DLL. It has been
going very well, and I am very impressed with ctypes. I want to call a
c function with a signature of: void func(int **cube), where the array
if ints in cube is modified by func. I want to setup cube with int
values, and access them after the call to func. I unerstand how to
setup the ctypes array, but how do I pass **cube to the function, and
how do I access the results?
it should be simple.
use something like (untestet):
b = POINTER(c_int)()
func(byref(b))
[snip two other similar alternatives]
That's true for "a pointer to a pointer to int", and it's valid if the
functions references **b or b[0][0] - but in this case int** probably
means "[pointer to] an array of arrays of int" and presumibly the function
will try to access b[3][2] (or whatever indices are in range).
The duality pointer/array in C is dangerous when defining interfases - you
have to know how the value is intended to be accessed.
(I assume the function modifies the integer values, but not the pointers
themselves)
# build an array of 10x10 ints
Arr10int = c_int * 10
Pint = POINTER(c_int)
PPint = POINTER(Pint)
Arr10pint = Pint * 10
a = Arr10pint()
for i in range(10):
a[i] = Arr10int()
... initialize the array ...
... load the function ...
# call the function
somefunction.argtypes = (PPint,)
somefunction.restype = None
somefunction(a)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list