Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events visualc中的简单回调&x2B+;_Events_Visual C++_Com_Event Handling_Callback - Fatal编程技术网

Events visualc中的简单回调&x2B+;

Events visualc中的简单回调&x2B+;,events,visual-c++,com,event-handling,callback,Events,Visual C++,Com,Event Handling,Callback,我是一名Linux程序员,不熟悉COM编程,我继承了一个程序,我现在正试图修改它。我有一个IDL文件,它具有以下的Debug接口,我试图在C++中设置回调。我一直在网上搜索,我发现了一些关于连接点的东西,但是我没有看到一个简单的例子,所以我想知道有没有人可以帮我 dispinterface: [ helpstring("Event interface"), helpcontext(0x00000006) ] dispinterface _DEvents { properties:

我是一名Linux程序员,不熟悉COM编程,我继承了一个程序,我现在正试图修改它。我有一个IDL文件,它具有以下的Debug接口,我试图在C++中设置回调。我一直在网上搜索,我发现了一些关于连接点的东西,但是我没有看到一个简单的例子,所以我想知道有没有人可以帮我

dispinterface:

[
  helpstring("Event interface"),
  helpcontext(0x00000006)
]
dispinterface _DEvents {
    properties:
    methods:
        [id(0x00000001), helpstring("Occurs when about to begin."), helpcontext(0x0000000d)]
        void Starting();
        [id(0x00000002), helpstring("Occurs at the beginning."), helpcontext(0x00000011)]
        void Begin();
        [id(0x00000003), helpstring("Occurs at the end."), helpcontext(0x00000012)]
        void End();
};
[
  odl
]
interface INotifySink : IUnknown {
    HRESULT _stdcall Starting();
    HRESULT _stdcall Begin();
    HRESULT _stdcall End();
};
coclass:

[
  helpstring("C Class"),
  helpcontext(0x0000009e)
]
coclass C {
    [default] interface IE;
    [default, source] dispinterface _DEvents;
};
接收器接口:

[
  helpstring("Event interface"),
  helpcontext(0x00000006)
]
dispinterface _DEvents {
    properties:
    methods:
        [id(0x00000001), helpstring("Occurs when about to begin."), helpcontext(0x0000000d)]
        void Starting();
        [id(0x00000002), helpstring("Occurs at the beginning."), helpcontext(0x00000011)]
        void Begin();
        [id(0x00000003), helpstring("Occurs at the end."), helpcontext(0x00000012)]
        void End();
};
[
  odl
]
interface INotifySink : IUnknown {
    HRESULT _stdcall Starting();
    HRESULT _stdcall Begin();
    HRESULT _stdcall End();
};
我找到了这两篇文章,但我无法理解它们的头绪:

我想我必须创建一个扩展INotifySink的新类,并实现这些函数,但之后我该怎么办

谢谢, 杰恩


另外,如果我需要提供更多信息,请告诉我,我将编辑此问题。谢谢。

你是在问如何使用现存的coclass事件吗?为此,您需要创建一个实现
\u DEvents
接口的对象,而不是一个新接口

比如:

 class EventSink : public _DEvents
 {
     AddRef() { ... }
     Release() { ... }
     QueryInterface(...) { ... }
     Starting() { printf("Starting happend\n"); }
     Begin() { ... }
     End() { ... }
 }
 EventSink *es = new EventSink;
 IE *objectOfInterest = ...;
 IConnectionPointContainer *cpc;
 objectOfInterest->QueryInterface(&cpc);
 IConnectionPoint *cp;
 cpc->FindConnectionPoint(__uuidof(_DEvents), &cp);
 cp->Advise(es, &cookie);
 objectOfInterest->somethingthatfiresanevent();

这有意义吗?

看看这没什么帮助。1) 我已经有了一个coclass(我现在把它添加到问题中)。2) VS2008没有向我显示“实现连接点…”选项您使用什么来实现coclass?MFC?ATL?MFC和ATL都有实现IConnectionPointContainer和IConnectionPoint等功能的工具。这不会让你失去理智。我所讨论的coclass来自第三方软件,该软件已经在我的继承程序中使用。我试着遵循Preet的链接,并使用ATL为自己创建了一个示例类,但这对我没有帮助。是的,这看起来很有意义。我会试试看,然后告诉你。我是否必须覆盖AddRef、Release和/或QueryInterface?现在我想知道第三方软件中的INotifySink接口有什么用处……您必须以某种方式实现它们(它们是纯虚拟的)。