Events 如何不受管理的C++;实现COM接收器

Events 如何不受管理的C++;实现COM接收器,events,com,Events,Com,我有一个c#COM服务器,它为事件处理定义了一些委托。 这是MSDN中的示例代码: using System; using System.Runtime.InteropServices; namespace Test_COMObject { public delegate void ClickDelegate(int x, int y); public delegate void ResizeDelegate(); public delegate void PulseDelegate(); /

我有一个c#COM服务器,它为事件处理定义了一些委托。 这是MSDN中的示例代码:

using System;
using System.Runtime.InteropServices;
namespace Test_COMObject
{
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 MyButtonEvents
{
    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(typeof(MyButtonEvents))]
public class MyButton
{
    public event ClickDelegate Click;
    public event ResizeDelegate Resize;
    public event PulseDelegate Pulse;

    public MyButton()
    {
    }
    public void CauseClickEvent(int x, int y)
    {
        Click(x, y);
    }
    public void CauseResizeEvent()
    {
        Resize();
    }
    public void CausePulse()
    {
        Pulse();
    }
}
}
<>但是MSDN只提供了一个VB实现COM客户端事件接收器的例子,有人能给我一个示例,说明了非托管C++是如何做到这一点的吗? 下面是实现COM事件接收器的vb示例

' 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

语言运行时通常隐藏从COM对象接收事件所涉及的大量管道。但是如果你在原始C++中这样做,那么你需要通过查询IConnectionPointContainer的接口指针来开始。这使您可以枚举所有输出接口。这样就可以获得特定接口的IConnectionPoint。然后调用其advice()方法来设置接收回调的接收器接口。这会给你一块饼干,你需要储存它。稍后当您想取消未经通知的呼叫时


它在MSDN库start中描述得相当好。

语言运行时通常隐藏从COM对象接收事件所涉及的大量管道。但是如果你在原始C++中这样做,那么你需要通过查询IConnectionPointContainer的接口指针来开始。这使您可以枚举所有输出接口。这样就可以获得特定接口的IConnectionPoint。然后调用其advice()方法来设置接收回调的接收器接口。这会给你一块饼干,你需要储存它。稍后当您想取消未经通知的呼叫时


在MSDN.Studio.S/.P>中描述得相当好,我创建了C++类:CaseCasButo:PuthTestSoCo对象:MyButoNevices,但我不能创建实例,编译器告诉我IDispath没有实现。最后,我导出了C函数,并使用C++库中的加载库来作为委托。我创建了C++类:CaseCasButo:PuthTestSoCopObj::MyButoNevices,但我不能创建实例,编译器告诉我IDispath没有实现。最后,我导出了一个c函数,并使用c#part中的load library将其作为委托进行处理。