How can I access data returned with a gpointer?
In some cases, for example in a callback function, you may get data as a gpointer instead of a python data type, making such data unreacheable from your python program. Although the gpointer data type provides no way of accesing the underlying pointer, there is a hack to do it using the gpointer’s conversion to string and reach the data using the ctypes module. Have a look at the following example, using the gtkmozembed widget. This function is the callback for the ‘open_uri’ widget signal. The second argument ‘uri’ should be a string, but all you’ll get is a gpointer. The gpointer is converted to string to get the pointer value in [13:-1] characters as an hex number, which may be converted to an integer. Using ctypes this integer is typecasted to a pointer to c style string (c_char_p), which is converted to a python string by the value method.
Related Questions
- Ive entered some numbers in a field in my Access data sheet, but when I attempt to sort on that field, the values are not returned in numerical order. What do I do?
- What if the returned ethnic group data form has an ethnic group indicated which does not appear to conform with the schools expectation of that childs ethnicity?
- What if I am put under pressure to ascribe an ethnic group for those pupils whose parents have not returned the ethnic group data collection form?