Reputation: 33
I'm loading a C library (.so
file) with ctypes
. Then I'm setting arguments and calling one function and got the error below;
ctypes.ArgumentError: argument 4: <class 'TypeError'>: expected LP_c_ushort instance instead of _ctypes.PyCSimpleType
As I guess it is related to the POINTER definition at the end of 3rd line. Can you help?
import ctypes
mylib = ctypes.cdll.LoadLibrary('./libfocas32.so')
mylib.cnc_allclibhndl3.argtypes = ctypes.c_wchar_p, ctypes.c_ushort, ctypes.c_long, ctypes.POINTER(ctypes.c_ushort)
mylib.cnc_allclibhndl3.restype = ctypes.c_long
h = ctypes.c_ushort
ret = mylib.cnc_allclibhndl3('192.168.1.1',9000,1,(h))
Upvotes: 1
Views: 272
Reputation: 10959
(1) h
must receive an instance of the type c_ushort
, therefore:
h = ctypes.c_ushort()
(2) Assuming that the pointer to h
is only used during the function call and shouldn't be stored longer, use
ret = mylib.cnc_allclibhndl3('192.168.1.1',9000,1,ctypes.byref(h))
Upvotes: 1