Re: Calling X11's XChangeProperty
2008-02-01 03:42:04 GMT
Welch, Donald J wrote: > Hello, > > I am trying to wrap X11's XChangeProperty API. What I'm having issues > with is the (uchar *)data parameter. I am trying to convert code that > looks like: > > int data = 1; > r = XInternAtom(...) > XChangeProperty(dsp, win, r, r, 32, 0, (uchar *)&data, 0) > > I specified the argtype for the data param as: c_char_p (there doesn't > seem to be a c_uchar_p type?) > > I've tried various combinations of pointer(), c_char_p, POINTER(), > etc. to massage the data value with no luck. Also, I do not understand > how to limit the data width to 32, as specified by the 32 in the call. > On a 64bit machine, an int can be 64 bits, right? > First, only use c_char_p where a foreign function can except a string literal as an argument. The (uchar *) parameter looks like it might pass out a value, so c_char_p is inappropriate. Instead declare the argument as a pointer, POINTER(c_byte), where c_byte is unsigned char. Second, you cannot use a Python int, a constant, as a parameter in this case. Use a mutable ctypes type instance. c_int32 is what you want since a C int is only guaranteed to be at least a 16 bit integer. Putting it all together: XChangeProperty.argtypes = [...., POINTER(c_byte), ...](Continue reading)
RSS Feed