Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ctypes return char array with null chars

126 views
Skip to first unread message

chris cannady

unread,
Apr 19, 2010, 5:29:05 AM4/19/10
to
Hi all,

I am passing a ctypes struct byref to a dll. When I get the struct
back, it looks like the char array in the struct was truncated at the
first null char. It should be 192 bytes long, but I know the 3rd
through 6th byte are null chars and the array was truncated right
before byte 3.

Is there any way to get the full array back including null chars?

Thanks

Mark Tolonen

unread,
Apr 19, 2010, 11:01:37 AM4/19/10
to pytho...@python.org

"chris cannady" <boo...@gmail.com> wrote in message
news:b103e85a-05d5-4195...@b33g2000yqc.googlegroups.com...

It could depend on how your struct is declared. Maybe this demo will help?

>>> x=(c_char*10)()
>>> x
<__main__.c_char_Array_10 object at 0x00A049E0>
>>> x.raw
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>> x.value
''

'value' prints it is a string, stopping at the first null. 'raw' dumps the
whole array.

-Mark


0 new messages