ctypes return char array with null chars

  • Follow


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
0
Reply booog35 (1) 4/19/2010 9:29:05 AM

"chris cannady" <booog35@gmail.com> wrote in message 
news:b103e85a-05d5-4195-a18f-bd143e9f57b8@b33g2000yqc.googlegroups.com...
> 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

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
Reply Mark 4/19/2010 3:01:37 PM


1 Replies
519 Views

(page loaded in 2.045 seconds)

Similiar Articles:













7/23/2012 5:24:34 PM


Reply: