python, ctypes, callbacks -- access violation when calling callback

resurtm resurtm at gmail.com
Sun Jul 19 11:15:33 EDT 2009


On 19 июл, 21:09, Christian Heimes <li... at cheimes.de> wrote:
> resurtm wrote:
> > Can anybody explain my errors when trying to pass callback to DLL
> > function?
>
> > Thanks for advices and solutions!
>
> You have to keep a reference to the callback alive yourself. ctypes
> doesn't increase the refernece counter of the function when you define a
> callback. As soon as the ref counter reaches 0, the function object is
> collected and the pointer to the callback is invalid.
>
> You could assign it to a module global or instance variable.
>
> Christian

Thanks for help Christian! It's working fine now! ;-)



More information about the Python-list mailing list