ctypes and pointers

per9000 per9000 at gmail.com
Mon Apr 16 12:39:13 CEST 2007


[This might be a double posting, if it isn't my previous post was
lost]

Look up "restype" in the ctypes library - it sets the return type from
a function. You may want to set it to c_void_p of something similar,
instead of the default int.

I made a similar discovery in my blog -
http://www.pererikstrandberg.se/blog/index.cgi?page=PythonCansiCombo
.

This example loads the function find_root from the dll
root_find_lib.dll into the variable "find". the restype of find is
then set to a c_double. This means that the item returned from C is a
C_double and not the default int.
    root_find_lib = windll.LoadLibrary("root_find_lib.dll")
    find = root_find_lib.find_root
    find.restype = c_double


You may already know this but 243666016 == 0E860C60 in different
bases.

HTH,
Per

[:)]-|--<

--

Per Erik Strandberg
.NET Architect - Optimization
Tomlab Optimization Inc.
http://tomopt.com/tomnet/





On 14 Apr, 19:25, "Diez B. Roggisch" <d... at nospam.web.de> wrote:
> Hi,
>
> I'm working under mac os x with the OpenCV-library that I load viactypes.
>
>  From a ObjectiveC-methodcall I get an integer, that "really" is a
> pointer to an IplImage-structure.
>
> I've got a function that takes such a pointer. But I don't find a way to
> pass it to that very function.
>
> These are the relevant parts of my code:
>
>          cvImage = self._f.cvImage()
>          print "Address of IplImage: %x" % cvImage
>          cvImage = c_void_p(cvImage)
>          print cvImage
>          cvImage2 = macopencv.cvCloneImage(cvImage)
>
> The output is
>
> 2007-04-14 19:22:53.910 SequenceGrabberTest[5320] Returning IplImage at
> Address of IplImage: e860c60
> e860c60
> c_void_p(243666016)
> 2007-04-14 19:22:53.915 SequenceGrabberTest[5320] Exception raised
> during posting of notification.  Ignored.  exception:
> exceptions.ValueError: depythonifying 'pointer', got 'int'
>
> The first line is actually from the ObjectivC-method, a log-statement.
>
> As one can see, the pointer is passed back as integer.
>
> But then I'm stuck.
>
> Any suggestions would be appreciated!
>
> diez





More information about the Python-list mailing list