python: ctypes, read POINTER(c_char) in python

后端 未结 2 369
情书的邮戳
情书的邮戳 2021-01-23 19:13

I have a ctypes field that is a POINTER(c_char) (it had to be, per the documentation, c_char_p didn\'t work for my application: https://docs.python.org/3.7/library/

2条回答
  •  失恋的感觉
    2021-01-23 19:56

    If you truly have a POINTER(c_char) type, it is subscriptable. In the future provide code that reproduces your issue:

    >>> p = cast(create_string_buffer(b'Hello, world!'),POINTER(c_char))
    >>> p
    
    >>> p[0]
    b'H'
    >>> p[:14]
    b'Hello, world!\x00'
    >>> cast(p,c_char_p).value  # only if known to be nul-terminated
    b'Hello, world!'
    

提交回复
热议问题