473,397 Members | 2,033 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,397 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 4021
"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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.