Click here to Skip to main content
15,879,490 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to create event based call from CLR and C#. But I don't have a idea about it. I'll explain my code below

My solution has a 3 separate project

Project1 (C++ with CLR support build) -> Project2(C++ with CLR support build)-> Project3 (C#)

Project1 (C++ with CLR Build support)

C++
class MB
{     
virtual void ShowMessage()
{
}
};

class MA
{
MB obj;
public: 

void PrintMessage()
{
obj.ShowMessage()
}
};


Project2 (C++ with CLR Build support)

C++
class WA : public MB
{
virtual void ShowMessage() override 
{

}
};

class WB
{
WA wObj;
void GetData()
{
    wObj= new MB();
    wObj.PrintMessage();


}
};

Basically if i call wObj.PrintMessage() function then it will call WA class ShowMessage() function. Till this point it's working fine.

Project3 (C#)

C++
Class MC
{
void PrintMessage()
{
}
};

I'm trying to invoke MC.PrintMessage() function whenever the MA.PrintMessage (Project1) function called.
Posted
Comments
Sergey Alexandrovich Kryukov 1-Nov-14 17:52pm    
What does it mean, exactly: "event-based call"? You can invoke an event instance from the declaring type only. In any other piece of code, you can also add a handler to the invocation list of this instance, and remove a handler. This is all you can do and all which you may possible need. C++ or C# don't make a difference. Any problems with that?
—SA

1 solution

You need to create an Event in your C++ code, and then subscribe to it in your .NET code: [^]; here's a specific example: [^].

Your C++ Event should be in a managed 'ref Class; see: [^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900