Assigning a new value to instances of pointer types c_char_p, c_wchar_p, and c_void_p changes the location of the memory they are pointing to, and not the contents of the memory block (of course not, since Python strings are immutable):
>>> s = "Hello, World" >>> c_s = c_char_p(s) >>> print c_s c_char_p('Hello, World') >>> c_s.value = "Hi, there" >>> print c_s c_char_p('Hi, there') >>> print s
You must be careful, however, do not pass them to functions that expect pointers to mutable memory. if you need modified blocks of memory, ctypes has a create_string_buffer function that creates them in different ways. the current contents of the memory block can be accessed (or changed) with an unprocessed property, if you want to access it as a NUL terminated string, use the line Property:
Says the ctypes tutorial. I understood from this that only if the function works with const char* , a python string will be passed. Keep in mind that it will not have zero completion.
I would suggest using create_string_buffer anyway.
source share