By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,165 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,165 IT Pros & Developers. It's quick & easy.

COM events in CSharp

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.