how to typecast a ctypes pointer to another one

Gelonida N gelonida at
Sat Jun 2 19:49:46 CEST 2012


I have a result from a call to a ctypes function of type c_void_p.

Now I'd like to convert it to a pointer to one of the structures, that I 

result = library.c_function(params)

class MyStruct(ctypes.Structure):
     _fields_ = [
         ('fourbytes', ctypes.c_char * 4)

I know I could (prior to calling) specify what datatype the function 
should return)

However as depending on some other conditions I have to interpret the 
return value either as pointer to one or another data type or another one.

Id' like to perform the casting after having received the value.

Thanks in advance for any pointers.

More information about the Python-list mailing list