Sink CUSTOM Windows Forms Events from Native C++ Classes?

G

Guest

I've managed to have my c++ CWinFormsDialog<...> class handle a standard
click event from my c# code as in:
http://msdn2.microsoft.com/en-us/library/af8w7d7d(VS.80).aspx

Is it possible to handle you own custom events with your own EventArgs in
the same way?

I get all sorts of strange compilation errors when I try:
GetControl()->MyEvent += MAKE_DELEGATE(System::EventHandler,
OnMyEventHandler);

void MyClass::OnMyEventHandler(System::Object^ pSender,
MYUSERCONTROL::MyEventArgs^ pEventArgs)
{
....
}


error C2870: 'MYNAMESPACE' : a namespace definition must appear either at
file scope or immediately within another namespace definition

error C4694: 'MYNAMESPACE::HelperFunctions': a sealed abstract class cannot
have a base-class 'System::MulticastDelegate'
 
S

Sheng Jiang[MVP]

I guess you need to use System::EventHandler<MYUSERCONTROL::MyEventArgs> as
the delegate type
 
G

Guest

Thanks, you can do it.
EVENT_DELEGATE_ENTRY( OnMyEventHandler, System::Object^,
MYUSERCONTROL::MyEventArgs^ );

Something weird was going on with my solution.
I'd done a rebuild on it, but doing a clean, closing and reopening visual
studio, and rebuilding seemed to sort things out...

I hope all these problems are finally sorted out in VS2008, but then again
we were promised they would be in vs2005
 

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