By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

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

P: n/a
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



Sep 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Sven,

"SvenC" <Cv*************@moc.tfgwrote in message
news:O0**************@TK2MSFTNGP06.phx.gbl...
Hi Mayur,

"Mayur" <ma***@activelement.comwrote in message
news:eZ**************@TK2MSFTNGP05.phx.gbl...
>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_IrcConnectio n,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::MessageEventHandle r __gc *)' : cannot create
a delegate handler for 'ircConnect::IrcConnection::MessageEventHandler'
from a non-member function or a member of an unmanaged class

I guess you will need to create a managed class in your MFC app which
implements the event handler. Use a member like
gcroot<YourManagedHandlerClass*m_handler;
When you create that instance pass it a pointer to your unmanaged class.
Use that pointer to forward the called managed handler to a member
function of your unmanaged class.

--
SvenC
Your guess is right and BTW: if you use VS2005, you can also use helpers
from msclr/event.h to solve the problem.

Marcus
Sep 1 '06 #2

P: n/a
Your guess is right and BTW: if you use VS2005, you can also use helpers
from msclr/event.h to solve the problem.
Just a s addition: Here is the link to an example:
How to: Sink Windows Forms Events from Native C++ Classes
http://msdn2.microsoft.com/en-us/library/af8w7d7d.aspx

Greetings
Jochen
Sep 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.