3

I am currently facing a problem with ctypes. I have a C function foo such that:

void** foo(int);

I have to define a callback function for the foo function. So:

FOO_FUNC = CFUNCTYPE(POINTER(c_void_p), c_int)
foo_c = lib.foo
foo.argtypes = [c_int]
foo.restype = POINTER(c_void_p)

Unfortunately, while calling a function taking this callback function as argument, it gives the error: TypeError: invalid result type for callback function

I can't see the problem... Can anyone help me? Thanks

Naked
  • 111
  • 3
  • 1
    Can you show the rest of the code? Like the part where you actually pass in the callback function? – Chris Eberle May 30 '11 at 06:08
  • I've actually highly simplified the situation. So i'm not sure it is gonna help you to see that part. I thought the problem came from the POINTER(c_void_p) type, that might be non accepted. The part you asked is something like: result = my_function_c(FOO_FUNC(foo_c)) – Naked May 30 '11 at 07:58

1 Answers1

1

Use c_void_p instead of POINTER(c_void_p). I think that should fix it. Also note that you cannot use composite types as callback return types: Issue5710

dgorissen
  • 6,207
  • 3
  • 43
  • 52