Array allocation

Koteswara Rao Ruvva <[email protected]> Sun, 21 Sep 2014 22:34:28 -0700
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Hello All,

I have the following getData function in a DLL that allocates memory and fill its contents.

extern "C" __declspec(dllexport) int getData(int *data) {
int size = 20;
               data = (int*) malloc(size*sizeof(int)); 

for (int i = 0; i < size; i++) {
data[i] = i*i;
}

return size;
}


I have the following Python code to call the getData function:

       mydll = ctypes.cdll.LoadLibrary('MathFuncs.dll')

       mydll.getData.argtypes = [ctypes.POINTER(ctypes.c_int)]
       mydll.getData.restype  = ctypes.c_int

       data = ctypes.POINTER(ctypes.c_int)

       size = mydll.getData(ctypes.POINTER(data))


When I execute, I get the following error:
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_long instance instead of _ctypes.PyCPointerType

I am not able to figure out the mistake. Could someone please correct me.

Thanks
Kotesh

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users