Access to a C++ base class

I have a C++ library that contains many classes. To access this classes it is possible to write a wrapper and forward the functions with

[DllImport (lib, CallingConvention = CallingConvention.Cdecl)]
public extern static own_type own_class_create_empty ();

But now there is a class, that is a base class for other classes. It contains some functions, that are virtual and they should be overwriten in the derived classes. The header looks like

class API Drawable : public BaseClass {
public:
    Drawable();
    void draw();
protected:
    virtual Rect onGetBounds() = 0;
    virtual void onDraw() = 0;

Now I should derive from this class in C#, because I would like to implement the virtual functions onGetBounds() and onDraw(). I assume, that I need a wrapper class to do this. This holds a handle to the C++ class and could call draw() via the normal DllImport path. No problem. But how to do this for the virtual methods? If I create a new instance of Drawable, than this virtual function point to a null pointer. Do I need a CLI project for this? And if yes, how could this look?

Thank you for your help.

Sign In or Register to comment.