Re: [ctypes-users] Prototypes with c_double
Brought to you by:
theller
From: Lenard L. <le...@te...> - 2007-12-27 21:42:41
|
Nicholas wrote: > Hi, > > Im not sure if this is a bug or something I dont understand. > import ctypes as c > libc = c.cdll.msvcrt > proto = c.CFUNCTYPE(c.c_double, c.c_double) The CFUNCTYPE is for wrapping a Python callable in C function for use as a C callback. > floor=proto(libc.floor) > floor(4.5) > > Traceback (most recent call last): > File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 206, in > 'calling callback function' > ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't > know how to convert parameter 1 > > This however works fine: > floor=libc.floor > floor.argtypes=c.c_double, floor.argtypes=[c.c_double] # argtypes is plural an so takes a list. > floor.restype = c.c_double > floor(5.6) > 5.0 > This is the correct way to assign argument and return types to an foreign C function. -- Lenard Lindstrom <le...@te...> |