1

I have a python script that calls methods exported out of C shared library.

How to pass a python class object as parameter to one of these methods.

Python code :

class module(object)
     def __init__(self, param1):
         self._param1 = param1

lib = CDLL("name")
mod = module1(10)
lib.func(pointer(mod))

C sample code:

struct module {
  int val;
};
extern "C" void func(struct module* data);

Can i access the value stored in module1 parameter in the c function "func".

Any more ideas how this functionality can be achieved ?

1 Answer 1

1

After bit of goggling found out a way:

you can declare a structure in python as :

class POINT(Structure):
    _fields_ = [("x", c_int),
               ("y", c_int)]

and pass the reference of this structure.

Refer : ctypes docs page

Sign up to request clarification or add additional context in comments.

Comments

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.