ctypes return char array with null chars

Discussion in 'Python' started by chris cannady, Apr 19, 2010.

  1. 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
     
    chris cannady, Apr 19, 2010
    #1
    1. Advertising

  2. chris cannady

    Mark Tolonen Guest

    "chris cannady" <> wrote in message
    news:...
    > 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
     
    Mark Tolonen, Apr 19, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl
    Replies:
    21
    Views:
    1,020
    Patricia Shanahan
    Aug 24, 2006
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,132
    Ian Collins
    May 9, 2006
  3. Replies:
    3
    Views:
    755
  4. Hongyu
    Replies:
    9
    Views:
    951
    James Kanze
    Aug 8, 2008
  5. Replies:
    0
    Views:
    524
Loading...

Share This Page