473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
2 3706
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
2
by: TogaKangaroo | last post by:
Hi, I'm trying to get intimate with my new copy of the .NET Pro developing environment, specifically C++ Visual Studio. I have a book (VC++ in 21 days) that I am going through following their...
0
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have...
3
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
0
by: Mayur | last post by:
Hello all, Im trying to call my .net c# library functions from my unmanaged vc++(dialog based MFC) application . From that application i want add the event handler for the event generated in c#...
1
by: Mayur | last post by:
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 :...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
1
by: Grant Schenck | last post by:
Hello, I built a client application using C# .NET 2.0. It runs fine at a number of customer sites. One customer is reporting several users getting problems. At start up it crashes with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.