Need help to grok c extension that needs to use callbacks with data

Thomas Heller theller at python.net
Fri Jun 20 04:54:32 EDT 2003


Jim West <Jim.West at checklogix.com> writes:

> Good day all,
>
>   Ok, I'm new to Python but not to programming in general.
>
>   I have a task where I need to implement a C extension to interface to
> a third-party DLL (yes, windoze).  I also need to do this "by hand" as
> opposed to using something like SWIG.
>
>   So far all my methods work like a charm.  Now I'm trying to implement
> some functions that use a pointer-to-function callback params that have
> data.
>
>   I've gone over the "RECIPE" that uses qsort and am trying to
> extrapolate that example into what I'm doing and am not being successful
> at it.
>
>   Python -> C Extension -> MethodWithCallback (void (*userFunc)(unsigned
> char *))
>
>   ...and I want the callback function to be a Python function.

Have you looked into ctypes? It is able to do this, even in pure Python.

http://starship.python.net/crew/theller/ctypes/

Thomas




More information about the Python-list mailing list