473,322 Members | 1,431 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,322 software developers and data experts.

How to create events in c# using COM interop

This is my COM wrapper written in c#.

using System.Runtime.InteropServices;
namespace SAFE_NAMESPACE_NAME
{
#region Events raised by your COM class
public delegate void Event1Handler(int i, int j);
[Guid("C37B4CE2-E6F0-404b-836A-722064BADBF1"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatc h) ]
public interface EVENTS_NAME
{
// TODO: Insert event handlers for events your class raises here.
[DispId(1)] void Event1(int i, int j);
}
#endregion
#region Interface published by your COM class
[Guid("117E0536-B80A-45b5-92BA-81B7AF5BAE5E"),
InterfaceType(ComInterfaceType.InterfaceIsDual) ]
public interface INTERFACE_NAME
{
// TODO: Insert functions your class publishes here.
[DispId(1)] int Function1(string s1, string s2);
}
#endregion
[Guid("251A0F17-2118-4884-BC55-4CEF4EA8A009"),
ProgId("[SAFE_NAMESPACE_NAME].[CLASS_NAME]"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(EVENTS_NAME)) ]
public class CLASS_NAME : INTERFACE_NAME
{
//
// TODO: Insert events raised by your class here.
//

public event Event1Handler Event;
public CLASS_NAME() : base()
{}
// TODO: Implement the methods of your class interface here.
public int Function1(string s1, string s2)
{
return 0;
}
}
}

c++ client
I am able to call the method exposed through interface.
#import "SAFE_NAMESPACE_NAME.tlb"
using namespace SAFE_NAMESPACE_NAME;
INTERFACE_NAME *t_my_interface;

CoInitialize(NULL);
SAFE_NAMESPACE_NAME::INTERFACE_NAMEPtr
q(__uuidof(SAFE_NAMESPACE_NAME::EVENTS_NAME));
t_my_interface = q;
t_my_interface->Function1("Hi","Hello");

But how to add Event handler in unmanaged c++ for the above Interface.
Waiting for the raply.

Dec 4 '06 #1
1 4000
"Mayur" <ma***@activelement.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
This is my COM wrapper written in c#.

using System.Runtime.InteropServices;
namespace SAFE_NAMESPACE_NAME
{
#region Events raised by your COM class
public delegate void Event1Handler(int i, int j);
[Guid("C37B4CE2-E6F0-404b-836A-722064BADBF1"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatc h) ]
public interface EVENTS_NAME
{
// TODO: Insert event handlers for events your class raises here.
[DispId(1)] void Event1(int i, int j);
}
#endregion
#region Interface published by your COM class
[Guid("117E0536-B80A-45b5-92BA-81B7AF5BAE5E"),
InterfaceType(ComInterfaceType.InterfaceIsDual) ]
public interface INTERFACE_NAME
{
// TODO: Insert functions your class publishes here.
[DispId(1)] int Function1(string s1, string s2);
}
#endregion
[Guid("251A0F17-2118-4884-BC55-4CEF4EA8A009"),
ProgId("[SAFE_NAMESPACE_NAME].[CLASS_NAME]"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(EVENTS_NAME)) ]
public class CLASS_NAME : INTERFACE_NAME
{
//
// TODO: Insert events raised by your class here.
//

public event Event1Handler Event;
public CLASS_NAME() : base()
{}
// TODO: Implement the methods of your class interface here.
public int Function1(string s1, string s2)
{
return 0;
}
}
}

c++ client
I am able to call the method exposed through interface.
#import "SAFE_NAMESPACE_NAME.tlb"
using namespace SAFE_NAMESPACE_NAME;
INTERFACE_NAME *t_my_interface;

CoInitialize(NULL);
SAFE_NAMESPACE_NAME::INTERFACE_NAMEPtr
q(__uuidof(SAFE_NAMESPACE_NAME::EVENTS_NAME));
t_my_interface = q;
t_my_interface->Function1("Hi","Hello");

But how to add Event handler in unmanaged c++ for the above Interface.
Waiting for the raply.
You have to implement an Event sink interface in C++, this question is largely OT for this
NG, google around for "implementing event sink" or "COM Connection points", and/or get a
good book on COM. Anyway without any support from template libraries like ATL and WFC,
you'll have a hard time to get this done in pure C++.

Willy.

Dec 4 '06 #2

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

Similar topics

2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
0
by: Anjali | last post by:
Hi All, I am trying to translates some of my IDLs into interop. All the methods of the IDL I am able to translate but am Getting stucked about how to manage the events that have been exposed by...
2
by: Markus Prediger | last post by:
Hi NG, I have an asp.net project that uses an vb6 com object for some database-manipulation (I cannot rewrite it in .net, sorry, its not my decision). I want it to be instanciated seperately...
1
by: Rethish R | last post by:
Hi, I have defined few Events in VB.Net, Register the DLL using "Register Interop for COM" Option. Now I have referred the class in VB 6.0. That is add the referrence for the DLL. But I am not...
3
by: James Wong | last post by:
Dear all, I have an old VB6 application which can create and access Excel object. The basic definition statements are as follows: Dim appExcel As Object Dim wkb1 As Excel.Workbook Dim wks1...
3
by: Stryker.Ninja | last post by:
First time poster, please be gentle :P I am using a third party ocx control in a C# 2.0 application. The interop seems to be working fine except for events. When I try and attach an event, it...
5
by: Richard Lewis Haggard | last post by:
I am trying to create multi-dimensioned arrays in conventional ASP pages and pass these arrays as arguments to functions that are in a C# interop assembly. ASP complains because it doesn't...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
0
by: Mayur | last post by:
This is my COM wrapper written in c#. using System.Runtime.InteropServices; namespace SAFE_NAMESPACE_NAME { #region Events raised by your COM class public delegate void Event1Handler(int i,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.