Re: How to get binary data to callback function
"Martin (gzlist)" <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
On 22/12/2009, Nikolaus Rath <[email protected]> wrote: > > When I define a callback function with a prototype of > > ctypes.CFUNCTYPE(None, ctypes.c_char_p, ctypes.c_int) You have the prototype wrong, c_char_p is for null-terminated strings: <http://docs.python.org/library/ctypes.html#ctypes.c_char_p> You want to use `ctypes.POINTER(ctypes.c_char)` instead for the definition. > The function receives a true Python string. However, my data isn't > actually \0 terminated, and I would like to call string_at(par1, par2) > to get the binary data. But how do I get ctypes to pass the c_char_p > object to my function, rather than the unwrapped string? The python callback function you write also needs to pass the second (size) argument to string_at which will otherwise assume null-termination. Martin ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev