Is it possible to automatically convert a Python int to a ctypes integer pointer using the argtypes attribute?
E.G.
import ctypes cfunc = ctypes.CDLL('somelib.so').somefunc i = 100 cfunc.argtypes = [ctypes.POINTER(ctypes.c_int)] cfunc(i) I was hoping that the argtypes attribute could be used to automatically convert the python integer...but I get an error
<type 'exceptions.TypeError'>: expected LP_c_int instance instead of int I assume it is because the argtype is actually made up of two ctypes calls?
Obviously, this works:
cfunc(ctypes.byref(ctypes.c_int(i))) but is a bit verbose, especially with multiple arguemnts!
from ctypes import c_int, byref, etcmakes the line considerably shorter. :)from ctypes import by_ref as Reven more.