I wrote my code like the example below:
public delegate void ClickDelegate(int x, int y);
public delegate void PulseDelegate();
[Guid("39D5B254-64DB-4130-9601-996D0B20D3E5"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IButton
{
void Work();
}
// Step 1: Defines an event sink interface (ButtonEvents) to be
// implemented by the COM sink.
[GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967") ]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ButtonEvents
{
void Click(int x, int y);
void Pulse();
}
// Step 2: Connects the event sink interface to a class
// by passing the namespace and event sink interface.
// ("EventSource.ButtonEvents, EventSrc").
[ComSourceInterfaces(typeof(ButtonEvents))]
public class Button : IButton
{
public event ClickDelegate Click;
public event PulseDelegate Pulse;
public Button() { }
public void CauseClickEvent(int x, int y) { Click(x, y); }
public void CausePulse() { Pulse(); }
public void Work() { /* Do some stuff */ }
}
This works fine with VB. When I define it like:
Dim WithEvents obj As Button
But I want to define it with the Interface like:
Dim WithEvents obj As IButton
This is not working 'cause the events are not visible from the IButton interface.
Is there a way to do this?