Actually I want to implement COM sink in C++ for C# server.
I am trying to implement event sink in C++ client, but it gives me member
not found error when call comes back from C# event raised.
Here are both C# source(taken from MSDN article: "Raising Events Handled by
a COM Sink") and C++ sink:
"VB client for the same C# source it is working fine"
//********** C# source ***************
using System;
using System.Runtime.InteropServices;
namespace EventSource
{
public delegate void ClickDelegate(int x, int y);
public delegate void ResizeDelegate();
public delegate void PulseDelegate();
// Step 1: Defines an event sink interface (ButtonEvents) to be
// implemented by the COM sink.
[GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967") ]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface ButtonEvents
{
void Click(int x, int y);
void Resize();
void Pulse();
}
// Step 2: Connects the event sink interface to a class
// by passing the namespace and event sink interface
// ("EventSource.ButtonEvents, EventSrc").
[ComSourceInterfaces(GetType(ButtonEvents))]
public class Button
{
public event ClickDelegate Click;
public event ResizeDelegate Resize;
public event PulseDelegate Pulse;
public Button()
{
}
public void CauseClickEvent(int x, int y)
{
Click(x, y);
}
public void CauseResizeEvent()
{
Resize();
}
public void CausePulse()
{
Pulse();
}
}
}
following statement in the attached client gives error "Member not found",
don't know what is going wrong.
hr = pButton->CauseClickEvent(x,x);
Any idea?
Thanks,
Sandip
"Adam Stirk" <.> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Here is some code I have recently used in C# for the DWebBrowserEvents2
COM interface.
Hope it helps, Adam
public class IEEvents : DWebBrowserEvents2
{
private int cookie = -1;
private UCOMIConnectionPoint icp;
private InternetExplorer m_IEClass;
public IEEvents(ref InternetExplorer IEClass)
{
//Call QueryInterface for IConnectionPointContainer
m_IEClass = IEClass;
UCOMIConnectionPointContainer icpc =
(UCOMIConnectionPointContainer)m_IEClass;
// Find the connection point for the
// DWebBrowserEvents2 source interface
Guid g = typeof(DWebBrowserEvents2).GUID;
icpc.FindConnectionPoint(ref g, out icp);
//Pass a pointer to the host to the connection point
icp.Advise(this, out cookie);
}
~IEEvents()
{
if (cookie != -1)
{
icp.Unadvise(cookie);
}
cookie = -1;
}
//Events Go Here
}
"sandip" <ss******@bindview.com> wrote in message
news:Ot***************@TK2MSFTNGP11.phx.gbl... Hi all,
I want to write a C# server that will invoke all umanaged COM client
methods; using something like connecitonpoint mechanism in C++.
Does anybody know how i can do this in C#?
tia,
Sandip Shahane