Calling member method on unmanaged C++ pointer from C# (I think)
- by Jacob G
I apologize in advance if this is a trivial question... I'm pretty C++ / unmanaged dumb.
Here's a simplified analog to my setup:
--In myUnmanagedObject.h in DLL:
class myUnmanagedObject
{
public:
virtual void myMethod(){}
}
--In MyControl.h in Assembly #1:
#pragma make_public(myUnmanagedObject)
[event_source(managed)]
public ref class MyControl :
public System::Windows::Forms::UserControl
{
public:
myUnmanagedObject* GetMyUnmanagedObject();
}
--in C# in Assembly #2:
unsafe
{
MyControl temp = new MyControl();
myUnmanagedObject* obj = temp.GetMyUnmanagedObject();
obj-myMethod();
}
I get a compile error saying that myUnmanagedObject does not contain a definition for myMethod. Assembly #2 references Assembly #1. Assembly #1 references DLL. If I compile the DLL with /clr and reference it directly from Assembly #2, it makes no difference.
How, from C#, do I execute myMethod ?