ctype and functions that return a pointer to a structure

hg hg at nospam.org
Sun Jul 1 16:09:28 EDT 2007


Hi,

I have the following code:
******************************************
from ctypes import * 
g_lib = cdll.LoadLibrary("libc.so.6")
class Struct_Password(Structure): 
    """ 
     
    """ 
    _fields_ = [ ('name', c_char_p), 
                ('code', c_char_p), 
                ('date', c_long), 
                ('min',  c_long), 
                ('max',  c_long), 
                ('warn', c_long), 
                ('inact', c_long), 
                ('expire', c_long), 
                ('flag', c_ulong) 
            ]
l_res =  g_lib.getspnam('john') 
l_struct = cast(l_res, POINTER( Struct_Password() ) ) 
print l_struct
******************************************

The exception I get is "unhashable type" - apparently cast only handles
simple types.

Is there a way to convert l_res to Struct_Password ?

Thanks,

hg




More information about the Python-list mailing list