I have a structure which contains character array on C side
stuct s
{
int x;
char buffer[100];
}
and on my python side I define
class myS(ctypes.Structure):
_fields_ = [("x", c_int),
("buffer",type(create_string_buffer(100)))]
Now, when I do
buf = create_string_buffer(64)
s1 = myS(10,buf)
It gives me error
TypeError: expected string or Unicode object, c_char_Array_100 found
I want a string which will be changed by my C function. how to do it?
You don’t have to create a buffer. The buffer is in the structure when you instantiate it.
Here’s a quick DLL:
And here’s Python code to call it:
Output: