Passing python objects as arguments to C/C++ function using ctypes

前端 未结 1 1905
悲哀的现实
悲哀的现实 2020-12-12 07:45

I have a dll with a function that takes PyObject as argument something like

void MyFunction(PyObject* obj)
{
    PyObject *func, *res, *test;

    //function         


        
相关标签:
1条回答
  • 2020-12-12 08:13

    I made the following changes to your code and it worked for me, but I'm not sure it is 100% correct way to do it:

    1. Use PYFUNCTYPE.
    2. Just pass the python class object.

    For example:

    prototype = c.PYFUNCTYPE(    
        c.c_char_p,                
        c.py_object
    )
    
    func = prototype(('MyFunction', libTest))
    
    func( MyClass )
    
    0 讨论(0)
提交回复
热议问题