473,811 Members | 3,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating event handler in unmanaged c++ code for event in managed code

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# dll which generates the event calles as Message Income
my c# dll code is like this

namespace ircConnect

{

public class IrcConnection

{

public delegate void MessageEventHan dler(object sender,MessageE ventArgs e);

public event MessageEventHan dler MessageIncome;

}

Here is my vc++ code.
#using <mscorlib.dll >

#using "ircConnect.dll " //This is the c# dll reference
__gc class GlobalObjects

{

#pragma push_macro("new ")

#undef new

public: static ircConnect::Irc Connection *iIRC =new
ircConnect::Irc Connection();
void OnMessageIncome ( Object* sender,
ircConnect::Irc Connection::Mes sageEventArgs* e )

{

MessageBox(NULL ,e->Message->Sender->ToString(),"", 1);
}

public:
__event ircConnect::Irc Connection::Mes sageEventHandle r*
MessageIncome;

#pragma pop_macro("new" )
};

void CMyMFCDlg::OnBn ClickedOk() //On Button click
{
#pragma push_macro("new ")
#undef new
GlobalObjects* m_proxyChat;
m_proxyChat = new GlobalObjects() ;
GlobalObjects *MyX = new GlobalObjects() ;
m_proxyChat->MessageIncom e += new
ircConnect::Irc Connection::Mes sageEventHandle r(MyX,GlobalObj ects::OnMessage Income);
//This is the event handler im trying to add

m_proxyChat->iIRC->Connect("testi ng");
m_proxyChat->iIRC->joinchannel("a bhishek","abhis hek","#guildae" );
#pragma pop_macro("new" )
}

But actually this event is not generated properly and function
OnMessageIncome will not be getting called;

So can u give me exact snippet for How to create event handler in unmanaged
vc++ code for event generated in Managed(c#) dll
Aug 30 '06 #1
0 1755

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
233
by: José Pérez Hernández | last post by:
Hi, Can i generate unmanaged code from managed code with some aplication ? I'm not so interested in the source code convertion than i do for the resulting build. I can imagine that if an aplication does not use framework services, it should be possible to make the translation to the target platform.
1
3726
by: seash | last post by:
class xyz{ public void somefunction{ if(this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) { m_varFolderPath = this.folderBrowserDialog1.SelectedPath; m_varFolderPath += "\\Iamlucky.txt";
2
2412
by: Brett Styles | last post by:
Hi Guys, I am trying to access a class in an unmanaged dll. I have created a wrapper managed class to access the functions I need but no matter what I try from the MSDN samples I can not get it to work with my code. I have a VB Net front end which need the access the unmanaged functions. The wrapper I wrote can be accessed but the wrapper will not compile when I refer to the unmanaged class. I have tried using header file for definitions...
12
6121
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls out of which unmanaged exception //get thrown
1
2264
by: RaKKeR | last post by:
Hi, I'm trying to wrap my unmanaged c++ code into a managed c++ wrapper. The problem is VC .NET doesn't seem to find the namespaces defined in my unmanaged code. Let's say I have a file "server.h" with a namespace server. When I include this file in another file that will be compiled as managed, the compiler gives me the following error: C2871: 'server' : a namespace with this name does not exist
4
2862
by: kimberly.walker | last post by:
Im very new to coding in C++ so use to coding in C#. My question is how to pass some values (string) from unmanaged code to managed code. I have two source files on a win32 console application one I used #pramga managed to change to managed code but I need to get the values from the unmanaged code and pass it to the managed code. Thanks...
2
1415
by: Kevin Sun | last post by:
I have a problem about non-managed code and managed code.Could you like to give me some suggestion? In a non-managed MFC application project, I add some managed codes and these files are setted into /clr:oldSyntax. But the problem is that when the debug exits, the non-managed object CApplicationApp(maybe all the global and static objects)'s ~ctor is called twice. In fact the managed code only is a function without any statement and is...
5
2405
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the correct value. Regardless what I set the variable to, the value that is returned for a long is always the same value. What's going on...can anyone help me? A short version of the code follows:
6
1553
by: B. | last post by:
my small project has two files, umg.cpp (unmanaged c++) and mged.cpp (MC++), and unmanged code will call managed code. However, I cannot debug from unmanged code into managed code. Can anyone help me to solve the problem?
1
3489
by: qwedster | last post by:
Howdy! I want to write a Custom Event Handler replicating textBox1_TextChanged event handler to update textBox2 with textBox1 text as I type. I tried the following in vain. Please help. The code snippet: // CustomEventArgs.cs
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.