0

I have different classes exported from native dll’s. The classes that is exported, inherit from multiple pure abstract classes (interfaces). The dll’s differ, in that the concrete class they export may inherit from different abstract classes. The native dll’s is loaded dynamically with LoadLibrary in a C++/CLI wrapper. Is there a way I can expose the class hierarchy (inheritance reltions) of the concrete native class in the dll. So that I can use the class as different interfaces in .NET.

Native interface

class PrimaryAbstractClass
{
  virtual void PrimaryMethod() = 0;
};

class SecondaryAbstractClass1
{
  virtual void Method1() = 0;
};

class SecondaryAbstractClass2
{
  virtual void Method2() = 0;
};

Dll 1

class ConcreteClass1: public PrimaryAbstractClass, public SecondaryAbstractClass1
{
  virtual void PrimaryMethod();
  virtual void Method1();
};

Dll 2

class ConcreteClass2: public PrimaryAbstractClass, public SecondaryAbstractClass2
{
  virtual void PrimaryMethod();
  virtual void Method2();
};

Intended C# usage (pseudo code)

PrimaryAbstractClassWrapper pacw = new Dll1.PrimaryAbstractClassWrapper();
((SecondaryAbstractClass2)pacw).Method2();
badger the bold
  • 421
  • 2
  • 4
  • COM does just that with interfaces. It works. Why not use that as a template? – 0xC0000022L Nov 20 '12 at 14:38
  • 1
    A C++/CLI ref class wrapper cannot inherit unmanaged classes, encapsulation is required. That puts a damper on the get-this-done-quick approach. – Hans Passant Nov 20 '12 at 15:13
  • @HansPassant Thanks. I can wrap all the native interfaces in .net interfaces, but the only way I can see to actually dynamically use that is with Reflection.Emit, is there another way? – badger the bold Nov 21 '12 at 06:25
  • @0xC0000022L Do you mean I should wrap the Native dll's classes in COM objects? – badger the bold Nov 21 '12 at 06:28

0 Answers0