Question

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

Was it helpful?

Solution

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

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

OTHER TIPS

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?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top