creting event handler client in vc++ for Source c# event

M

Mayur

Hello all,

Can any one have the source of How to add event handler in unmanaged MFC
application for
event source which is in Managed(c# class library).

Here is the Event Source code
:
namespace ircConnect

{

public class IrcConnection

{

public delegate void MessageEventHandler(object sender,MessageEventArgs e);

public event MessageEventHandler MessageIncome;

}End Class







Event Client

void CADONET_MFCDlg::OnFilling() //This is the MFC dialog box event

{

#pragma push_macro("new")

#undef new

try

{

m_IrcConnection =new IrcConnection();

FileWatcherEvents *f=new FileWatcherEvents();

m_IrcConnection->add_MessageIncome=new
IrcConnection::MessageEventHandler(m_IrcConnection,OnMessageIncome);

};



im using gcroot template
gcroot<IrcConnection*> m_IrcConnection;

gcroot<IrcMessage*> m_IrcMessage;



void static OnMessageIncome( Object* sender,
IrcConnection::MessageEventHandler* e );

but the compile time error generated as follows

error C3363: 'void CADONET_MFCDlg::OnMessageIncome(System::Object __gc
*,ircConnect::IrcConnection::MessageEventHandler __gc *)' : cannot create a
delegate handler for 'ircConnect::IrcConnection::MessageEventHandler' from a
non-member function or a member of an unmanaged class
 
W

Willy Denoyette [MVP]

| Hello all,
|
| Can any one have the source of How to add event handler in unmanaged MFC
| application for
| event source which is in Managed(c# class library).
|
| Here is the Event Source code
| :
| namespace ircConnect
|
| {
|
| public class IrcConnection
|
| {
|
| public delegate void MessageEventHandler(object sender,MessageEventArgs
e);
|
| public event MessageEventHandler MessageIncome;
|
| }End Class
|
|
|
|
|
|
|
| Event Client
|
| void CADONET_MFCDlg::OnFilling() //This is the MFC dialog box event
|
| {
|
| #pragma push_macro("new")
|
| #undef new
|
| try
|
| {
|
| m_IrcConnection =new IrcConnection();
|
| FileWatcherEvents *f=new FileWatcherEvents();
|
| m_IrcConnection->add_MessageIncome=new
| IrcConnection::MessageEventHandler(m_IrcConnection,OnMessageIncome);
|
| };
|
|
|
| im using gcroot template
| gcroot<IrcConnection*> m_IrcConnection;
|
| gcroot<IrcMessage*> m_IrcMessage;
|
|
|
| void static OnMessageIncome( Object* sender,
| IrcConnection::MessageEventHandler* e );
|
| but the compile time error generated as follows
|
| error C3363: 'void CADONET_MFCDlg::OnMessageIncome(System::Object __gc
| *,ircConnect::IrcConnection::MessageEventHandler __gc *)' : cannot create
a
| delegate handler for 'ircConnect::IrcConnection::MessageEventHandler' from
a
| non-member function or a member of an unmanaged class
|
|
|
|

THis is not a C# issue, please post C++ questions to the vc NG
<microsoft.public.dotnet.languages.vc> , that said, the error message tells
it all, your MessageEventHandler' delegate must be created from a managed
class.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top