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

COM events in CSharp

Hi,
I have an application that was written as ATL project which uses as a server
application and has a COM class which implements IConnectionPoints interface
(to fire events).
I have clients applications which uses the server application (the clients
are written in several languages).
In the VB client I use "WithEvents" option to recieve the events.
In the VC client I create a class derived from IDispEventImpl to recieve the
events.

What do I do in CSharp client ???

Yoav.
Feb 1 '07 #1
3 3211
Add reference to your ATL object.
Add code like MyAtlObject.<yourATLObjectsEventName>+=<event handler>.
Should do.

"Yoavo" <yo**@cimatron.co.ilha scritto nel messaggio
news:OG**************@TK2MSFTNGP02.phx.gbl...
Hi,
I have an application that was written as ATL project which uses as a
server application and has a COM class which implements IConnectionPoints
interface (to fire events).
I have clients applications which uses the server application (the clients
are written in several languages).
In the VB client I use "WithEvents" option to recieve the events.
In the VC client I create a class derived from IDispEventImpl to recieve
the events.

What do I do in CSharp client ???

Yoav.


Feb 1 '07 #2
I have similar problem - trying to handle some key press events in a
DataGridView, and I added code like this:
this.dataGridView.KeyPress += new
System.Windows.Forms.DataGridViewCellEventHandler( this.dataGridView_KeyPress);
to my frmMain.Designer.cs,
and the corresponding dataGridView_KeyPress fnc to my frmMain.cs.
But the compiler (VS .NET 2005) complains:
Error: Cannot implicitly convert type
'System.Windows.Forms.DataGridViewCellEventHandler ' to
'System.Windows.Forms.KeyPressEventHandler'

I am used to adding event handlers by double clicking the target element in
my form's design view, but that doesn't work when dealing with handling
keystrokes or cell selection changes and such. Is there a semi-automated way
in the IDE to create event handlers other than that?
Thank you,
Dave

"Laura T." wrote:
Add reference to your ATL object.
Add code like MyAtlObject.<yourATLObjectsEventName>+=<event handler>.
Should do.

"Yoavo" <yo**@cimatron.co.ilha scritto nel messaggio
news:OG**************@TK2MSFTNGP02.phx.gbl...
Hi,
I have an application that was written as ATL project which uses as a
server application and has a COM class which implements IConnectionPoints
interface (to fire events).
I have clients applications which uses the server application (the clients
are written in several languages).
In the VB client I use "WithEvents" option to recieve the events.
In the VC client I create a class derived from IDispEventImpl to recieve
the events.

What do I do in CSharp client ???

Yoav.
Feb 1 '07 #3
In order to make things more clear, here is my code:
In the server, this is the definitions of the COM interface and its events
handler:
interface IDog : IDispatch

{

[id(1), helpstring("method Bark")] HRESULT Bark();

};

[

uuid(17CEB032-D336-4F3C-85E3-90D879D38F1F),

version(1.0),

helpstring("DogTest 1.0 Type Library")

]

library DOGTESTLib

{

importlib("stdole32.tlb");

importlib("stdole2.tlb");

[

uuid(22807A6E-50E6-49F7-904C-746A27110243),

helpstring("_IDogEvents Interface")

]

dispinterface _IDogEvents

{

properties:

methods:

[id(1), helpstring("method OnBark")] HRESULT
OnBark();

};

-----------------------------

This is the implementation (in the server) of IDog::Bark:

STDMETHODIMP XDog::Bark()

{

Fire_OnBark();

return S_OK;

}

-----------------------------

This is the implementation (in the server)of the IConnectionPoints
interface:

template <class T>

class CProxy_IDogEvents : public IConnectionPointImpl<T, &DIID__IDogEvents,
CComDynamicUnkArray>

{

Public:

HRESULT Fire_OnBark()

{

...

}

};

-----------------------------

And this is my c# client implementation:

namespace DogCsClient

{

public partial class Form1 : Form

{

class MyDogEvents : DOGTESTLib._IDogEvents

{

#region _IDogEvents Members

public void OnBark()

{

MessageBox.Show("OnBark event !!!");

}

#endregion

};

DOGTESTLib.Dog mDog;

public Form1()

{

InitializeComponent();

mDog = new DOGTESTLib.Dog();

}

private void button1_Click(object sender, EventArgs e)

{

mDog.Bark();

}

}

}

What should I do inorder to recieve OnBark() event in my c# client ???


"Laura T." <LT@NOWHERE.COMwrote in message
news:eX**************@TK2MSFTNGP02.phx.gbl...
Add reference to your ATL object.
Add code like MyAtlObject.<yourATLObjectsEventName>+=<event handler>.
Should do.

"Yoavo" <yo**@cimatron.co.ilha scritto nel messaggio
news:OG**************@TK2MSFTNGP02.phx.gbl...
>Hi,
I have an application that was written as ATL project which uses as a
server application and has a COM class which implements IConnectionPoints
interface (to fire events).
I have clients applications which uses the server application (the
clients are written in several languages).
In the VB client I use "WithEvents" option to recieve the events.
In the VC client I create a class derived from IDispEventImpl to recieve
the events.

What do I do in CSharp client ???

Yoav.



Feb 4 '07 #4

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

Similar topics

4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
3
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
2
by: John Olbert | last post by:
Could someone recommend an indepth book(s) or set of articles on Events, Threading and Delegates under C#? We have run into a problem in which when an event was subscribed in code that the...
2
by: SimonZ | last post by:
In ASP.NET 2.0, C# I can see object events only in design view. That is very disturbing. I don't use design view at all. I work with source view and code behind. If you change language to...
9
by: CuriousGeorge | last post by:
Can someone explain why this code DOES NOT raise a null reference exception? //////////////////////////// Program.cs ///////////////////////////////////////////// using System; using...
2
by: Itzik | last post by:
Hi all, How can i handle windows events. For example i what to know all times when new folder creates. Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...
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,...

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.