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.