ArgumentError when passing ctypes array to C function

Stephen

I'm trying to use a C function copyDataContent that copies float data from a C struct object I point to with pointer DataHandle into a location given by a float pointer. I have included the function prototype for this function. I can get the dimensions of this data via another function in the library. My code is below.

Prototype of copyDataContent

void copyDataContent(DataHandle DataSource, float* Destination);

Here's where things go wrong:

data = createData()
size0 = getDataPropertyInt(data,0)
size1 = getDataPropertyInt(data,1)
arrC = C.POINTER(C.c_float*size0*size1)
libc.copyDataContent.argtypes = [DataHandle,C.POINTER(C.c_float)]
libc.copyDataContent(data,arrC)

Console output:

ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_float instance instead of _ctypes.PyCPointerType

^from the line where I actually call copyDataContent

But here's what the console tells me about arrC

arrC
Out[88]: __main__.LP_c_float_Array_0_Array_0

Can anyone shed any light on what is going wrong? ctypes docs aren't helping

Mark Tolonen

arrC = C.POINTER(C.c_float*size0*size1) creates a type not an instance.

If you want the instance of an array, use arrC = (C.c_float*size0*size1)().

to pass it to a float* parameter, use libc.copyDataContent(data,cast(arrC,POINTER(c_float))).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Python

CPPYY/CTYPES passing array of strings as char* args[]

From Dev

How to interface a NumPy complex array with C function using ctypes?

From Dev

How does ctypes know when to throw ArgumentError, but only sometimes?

From Dev

Python ctypes: Passing an array of strings

From Dev

proper pattern to use when passing an array to a function

From Dev

ctypes.ArgumentError when calling DLL functions with Python

From Dev

ctypes.ArgumentError when using kivy with pywinauto

From Dev

C - Passing a pointer to an array to a function to print the array

From Dev

Passing array of struct to function in C

From Dev

Returning a C array from a C function to Python using ctypes

From Dev

Forcing an array size in a function parameter in C when passing an array

From Dev

Passing pointer of an array to a function in C

From Dev

Passing a pointer to an array in a function in C

From Dev

Python ctypes function returns ValueError when C function returns NULL

From Dev

Passing an Array as Argument to Function in C

From Dev

Passing a ctypes callback function around in C causes memory related problems

From Dev

Python -passing imgdata pointer to a function in C using ctypes

From Dev

exception when passing array in function to scanf

From Dev

Passing an uninitialized array to a function in C

From Dev

Pass byte numpy array to C function using ctypes

From Dev

Calling C functions via Python ctypes: why does passing uints to a function expecting size_t work?

From Dev

Passing a python list to "c" DLL function which returns array data using ctypes

From Dev

Error when passing multidimensional char array to a void function in C

From Dev

Passing Numpy array to C with Ctypes differs between Linux and Windows

From Dev

Problem when passing multidimensional array to a function in C

From Dev

Error when passing 2D array to function in c

From Dev

Error When Passing String array to function in C++

From Dev

Passing an array of pointers to function in C

From Dev

Passing an array of structs to a function in C

Related Related

  1. 1

    CPPYY/CTYPES passing array of strings as char* args[]

  2. 2

    How to interface a NumPy complex array with C function using ctypes?

  3. 3

    How does ctypes know when to throw ArgumentError, but only sometimes?

  4. 4

    Python ctypes: Passing an array of strings

  5. 5

    proper pattern to use when passing an array to a function

  6. 6

    ctypes.ArgumentError when calling DLL functions with Python

  7. 7

    ctypes.ArgumentError when using kivy with pywinauto

  8. 8

    C - Passing a pointer to an array to a function to print the array

  9. 9

    Passing array of struct to function in C

  10. 10

    Returning a C array from a C function to Python using ctypes

  11. 11

    Forcing an array size in a function parameter in C when passing an array

  12. 12

    Passing pointer of an array to a function in C

  13. 13

    Passing a pointer to an array in a function in C

  14. 14

    Python ctypes function returns ValueError when C function returns NULL

  15. 15

    Passing an Array as Argument to Function in C

  16. 16

    Passing a ctypes callback function around in C causes memory related problems

  17. 17

    Python -passing imgdata pointer to a function in C using ctypes

  18. 18

    exception when passing array in function to scanf

  19. 19

    Passing an uninitialized array to a function in C

  20. 20

    Pass byte numpy array to C function using ctypes

  21. 21

    Calling C functions via Python ctypes: why does passing uints to a function expecting size_t work?

  22. 22

    Passing a python list to "c" DLL function which returns array data using ctypes

  23. 23

    Error when passing multidimensional char array to a void function in C

  24. 24

    Passing Numpy array to C with Ctypes differs between Linux and Windows

  25. 25

    Problem when passing multidimensional array to a function in C

  26. 26

    Error when passing 2D array to function in c

  27. 27

    Error When Passing String array to function in C++

  28. 28

    Passing an array of pointers to function in C

  29. 29

    Passing an array of structs to a function in C

HotTag

Archive