views:

626

answers:

3

I have an unmanged C++ class I have written in an unmanged dll. I have a managed dll that references the unmanaged dll. Can a class in the managed dll derive from the unmanaged class?

Using Visual Studio 2008

+3  A: 

You can't. Managed classes are garbage collected and created on CLR heap. Unmanaged classes are allocated in unmanaged heap. How could you be able to create an object whose data is partially in managed heap and its base data in unmanaged heap.

You should try other techniques, to wrap a managed container over the unmanaged thing or vice versa and derive from that, probably.

Mehrdad Afshari
AFAIK, objects, not classes, are allocated. And unmanaged objects can be allocated either in the stack or the heap.You're right about wrapping the unmanaged object inside a managed object, though.
Eduardo León
You are right about the terminology. However, I wanted to emphasis on how you declare your classes. That's why I used managed classes instead of managed objects.
Mehrdad Afshari
+1  A: 

You can't yet. Herb Sutter wrote an extensive C++/CLI Design Rationale where he hints such things may indeed be possible one day. However, it seems that Microsoft has stopped further development of C++/CLI?

Dan
A: 

The best you can do is wrap you unmanaged class in a manager wrapper and then derive from that.

Colin Desmond