How to advise in C++ on an event in c# ?
I created an interface in c# and I tryied to import the tlb in c++ and to
advise me on the event in the interface.
I use the following sample but it's base on a VB client.
http://msdn2.microsoft.com/en-us/library/dd8bf0x3.aspx
Here is the code c# of the interface
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.InterfaceIsIDispatch)]
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();
}
}
}
I need to follow the same step as the VB code bellow but in C++.
' COM client (event sink)
' This Visual Basic 6.0 client creates an instance of the Button class and
' implements the event sink interface. The WithEvents directive
' registers the sink interface pointer with the source.
Public WithEvents myButton As Button
Private Sub Class_Initialize()
Dim o As Object
Set o = New Button
Set myButton = o
End Sub
' Events and methods are matched by name and signature.
Private Sub myButton_Click(ByVal x As Long, ByVal y As Long)
MsgBox "Click event"
End Sub
Private Sub myButton_Resize()
MsgBox "Resize event"
End Sub
Private Sub myButton_Pulse()
End Sub
In the interface ButtonEvents, i try to use event declaration instead of
void method declaration and the generated file created by the tlb include
methos wrapper like Click_add and Click_remove but i don't know how to use it.
Thanks you