Re: How to pass String BYREF to C function?

marco cassisa <[email protected]>
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Hi

2010/8/18 Andrew Wilson <[email protected]>

> 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 <[email protected]
> > 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

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.