10

I have a C function that the doxygen looks like this:

long function( classA * obj1,
               classB * obj2,
               classC ** obj3,
               long value,
               const char * name1,
               const char * name2,
               classD ** obj4,
               classD ** obj5,
               classD ** obj6 
               )    

I need to call it from python and get the 3 last arguments to pass to another dll. Currently I can call the DLL fine, but if I try to pass the last 3 arguments to the other function I get an error like this:

WindowsError: exception: access violation writing 0x0000000000000000

I am probably doing something wrong in the ctypes side of things and I would appreciate some light on how to use it...

The second DLL looks like this:

int function2(ClassD *  obj4)   

And currently I "assemble" the last 3 arguments like this:

  temp=ctypes.c_long*1
  obj = temp(0)

Also, is there any way of going from ctypes to swig? Apparently I can do the other way around using the long function.

1 Answer 1

10

I had to do some extra digging to figure out how C-types works and the following seems to work. For function I needed to create an array:

arg = (ctypes.POINTER(ctypes.c_double) * 1)()

and pass it by reference to the function:

ctypes.byref(arg)

For the second function I would just pass one element of the array I created:

arg[0]
Sign up to request clarification or add additional context in comments.

1 Comment

wow, you came back 2 months later and answered your question! kudos and thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.