Re: 2.6 - 3.x bytearray from c_char_ p
Thomas Stover <[email protected]> Tue, 17 May 2011 18:05:36 -0500
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Turns out it actually wasn't working. It stopped on bytes of value 0
thinking it was a NULL termination.
I found in the docs:
class ctypes.c_char_p¶
Represents the C char * datatype when it points to a zero-terminated
string. For a general character pointer that may also point to binary data,
POINTER(c_char) must be used. The constructor accepts an integer address,
or a string.
So the callback argument is of type POINTER(c_char) instead of c_char_p.
Given a parameter, Pointer, of such a type, to get a usable string of
"Length" size, use the notation Jeff gave:
def Callback(Pointer, Length):
Usable = Pointer[:Length]
--
www.thomasstover.com
FLYNN LIVES!
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users