all groups > dotnet interop > april 2008 >
You're in the

dotnet interop

group:

Class in mixed mode project inheriting from class in unmanaged project?



Class in mixed mode project inheriting from class in unmanaged project? Chris Ashley
4/24/2008 7:28:23 AM
dotnet interop: I need to implement callbacks from methods in an unmanaged DLL to a
mixed mode DLL. I'm having trouble finding examples on how to do this
and all the examples I find seem to revolve around interactions
between managed/unmanaged classes in a single mixed mode DLL.

Is it possible for me to define a class in my unmanaged project,
inherit from it in an unmanaged class in my mixed mode project, and
then hold instances of managed objects in this class as well?

EG:

Project A (unmanaged class, unmanaged project)

class Unmanaged
{
public:
virtual void Test(DWORD dwTest) = 0;
};

Project B (unmanaged class, mixed mode project)

class Managed : public Unmanaged
{
public:
void Test(DWORD dwTest); // Unmanaged callback method to be
implemented
gcroot<String*> m_strTest; // CLR type
};

It this possible, and are there any alternative ways I can accomplish
this?

Thanks in advance,

RE: Class in mixed mode project inheriting from class in unmanaged pro Adam Root
4/29/2008 11:41:00 AM
Chris,

I'm not a CLI/C++ expert, but I am almost certain that a managed class
cannot inherit from an unmanaged class. You can, however, have an unmanaged
class in your mixed mode project inherit from a class in your native project.

That said, you can certainly have a managed class that wraps (references) an
unmanaged class.

Adam

[quoted text, click to view]
AddThis Social Bookmark Button