Hi Artem,
On 11 March 2016 at 11:11, Artem Zhukov <
green....@gmail.com> wrote:
> I need to share a python class with a C++ application by the means of DLL.
You'll need to give more examples about what you really want before we
can help. The CFFI interface is about exchanging C data and functions
with Python; it contains no built-in way to translate between C++
classes and instances and Python classes and instances. It is still
possible to do it, but you need to go via C.
So the first step is to design a C API for your C++ classes. This C
API goes into the .h file and possibly a .c file. This must be done
upfront without thinking about Python at all. Only then, you can
access this C API with CFFI. You need ffi.new_handle() to attach a
Python object to "void *" data, and store this "void *" data somewhere
inside the C API (maybe inside a new member in the C++ instances).
How to do it exactly depend entirely of the details of your use case.
If you only know C++, and not reasonably well C and Python, then it
can be a bit difficult. Maybe look at alternatives, like for example
PyPy's "cppyy" (there are others), that are direct C++-Python bridges.
The trade-off: CFFI is lower-level but lets you do anything; these
other C++-Python bridges are typically higher-level but assume some
programming model---which are often respected in C++.
A bientôt,
Armin.