Re: [ctypes-users] How to pass String BYREF to C function?
Brought to you by:
theller
From: marco c. <mar...@gm...> - 2010-08-18 12:34:00
|
Hi 2010/8/18 Andrew Wilson <and...@al...> > Hey Lynton, > Your c code needs to properly terminate the string with a '\n' in order > for python to print the result correctly. > Andrew > > On Wed, Aug 18, 2010 at 8:11 AM, Lynton Grice <lyn...@lo... > > wrote: > >> .... >> >> I get the following output in WingIDE >> >> >> >> helloö >> >> but create_string_buffer() shouldn't take care of terminating the string with 0? following http://docs.python.org/library/ctypes.html You should be careful, however, not to pass them to functions expecting pointers to mutable memory. If you need mutable memory blocks, ctypes has a create_string_buffer() function which creates these in various ways. The current memory block contents can be accessed (or changed) with the raw property; if you want to access it as NUL terminated string, use the value property: anyway, the second argument of create_string_buffer() can be the length of the string buffer array, so you can set it to the string's lenght +1 bye marco |