I have been trying to pass a struct in Ctypes. But the function call is throwing a format error.
This is my C function:
typedef struct Point2Struct {
double x, y;
} Point2;
Point2 test(Point2 k)
{
return k;
}
The python call is as follows:
class Point2(Structure):
_fields_ = [('x',c_double),('y',c_double)]
lib.test.argtypes=[Point2]
lib.test.restype=Point2
p = Point2(1.1, 2.2)
g = lib.test(p)
print g.x, g.y
When I call the function through CDLL, I get:
ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
with WinDLL, I get:
ValueError: Procedure probably called with too many arguments (16 bytes in excess)
I compiled the C code into a DLL using (Mingw) gcc under Windows 7.
gcc -shared -o test.dll test.o
I also tried using a .so file with:
gcc -shared -Wl,-soname,test-o test.so -fPIC test.c
But I get the same errors.
What am I doing wrong ? Should I compile with any specific option ?
__declspec(dllexport)and__cdeclto the function? Or, alternatively, have you tried writing C code that loads and uses your DLL the same way you want to withctypes? - abarnert