[
object,
uuid(AECE8D0C-F902--A374-ED3A0EBB6B49),
dual,
nonextensible,
pointer_default(unique)
]
interface ICallbacks : IUnknown
{
[id()] HRESULT UserExit([in] int errorCode, [in] BSTR errorMessage);
[id()] HRESULT UserAttemptingReconnection();
[id()] HRESULT UserReconnected();
}; [
object,
uuid(B98A7D3F-651A-49BE--2B1D8C896E9E),
dual,
nonextensible,
pointer_default(unique)
]
interface ICerberusSession : IDispatch {
...
[id()] HRESULT SetCallbacks([in] ICallbacks* callbacks);
};

上面只是创建了一个函数指针回调,也算是可以用了但并非标准windows事件。

创建标准windows事件步骤如下:

.Create a new ATL DLL Project. I've called it ATLEventTest1.
.Build Project.
.Class View: Right clicked on ATLEventTest1, Add a new ATL Simple Object class. Call it MyObject.
.Create the definition with a) Apartment Threading b) Dual Interface c) Connection points and whatever else you need.
.Rebuild Project.
.Class View: Locate the ATLEventTest1Lib library, right click on _MyObjectEvents, and "Add Method".
.Method is of void return type, named someEvent, and takes an int testParam with parameter attribute [in].
.You should see "[in] int testParam" as a result of adding the parameter.
.On the IDL Attributes tab, change the id if necessary. Click Finish.
.Class View: Right click on CMyObject, go to Add... , go to Implement Connection Point.
.Select _IMyObjectEvents and click ">" to move it to the implemented connection points list. Click Finish.
.Rebuild.
.Now, in your CMyObject class, you should be able to call Fire_someEvent(). You will see a new method in your ATLEventTest1.idl file under the dispinterface _IMyObjectEvents; the header file _IMyObjectEvents_CP.h file will be created and will create the broadcast code for Fire_someEvent().

Adding Connection Points to an existing class:

The ATL Tutorial demonstrates how to create a control with support for connection points, how to add events, and then how to implement the connection point. ATL implements connection points with the IConnectionPointImpl class.

To implement a connection point, you have two choices:

•Implement your own outgoing event source, by adding a connection point to the control or object.

•Reuse a connection point interface defined in another type library.

In either case, the Implement Connection Point Wizard uses a type library to do its work.

To add a connection point to a control or object

.Define a dispinterface in the library block of the .idl file. If you enabled support for connection points when you created the control with the ATL Control Wizard, the dispinterface will already be created. If you did not enable support for connection points when you created the control, you must manually add a dispinterface to the .idl file. The following is an example of a dispinterface. Outgoing interfaces are not required to be dispatch interfaces but many scripting languages such as VBScript and JScript require this, so this example uses two dispinterfaces:
[
uuid(3233E37D-BCC0--B277-48AE6B61224A),
helpstring("Buddy Events")
]
dispinterface DBuddyEvents
{
properties:
methods:
}; Use either the uuidgen.exe or guidgen.exe utility to generate a GUID. .Add the dispinterface as the [default,source] interface in the coclass for the object in the project's .idl file. Again, if you enabled support for connection points when you created the control, the ATL Control Wizard will create the [default,source] entry. To manually add this entry, add the line in bold:
coclass Buddy
{
[default] interface IBuddy;
[default,source] dispinterface DBuddyEvents;
}; See the .idl file in the Circ ATL sample for an example. .Use Class View to add methods and properties to the event interface. Right-click the class in Class View, point to Add on the shortcut menu, and click Add Connection Point. .In the Source Interfaces list box of the Implement Connection Point Wizard, select Project's interfaces. If you choose an interface for your control and press OK, you will: •Generate a header file with an event proxy class that implements the code that will make the outgoing calls for the event. •Add an entry to the connection point map. You will also see a list of all of the type libraries on your computer. You should only use one of these other type libraries to define your connection point if you want to implement the exact same outgoing interface found in another type library. To reuse a connection point interface defined in another type library .In Class View, right-click a class that implements a BEGIN_COM_MAP macro, point to Add on the shortcut menu, and click Add Connection Point. .In the Implement Connection Point Wizard, select a type library and an interface in the type library and click Add. .Edit the .idl file to either: •Copy the dispinterface from the .idl file for the object whose event-source is being used. •Use the importlib instruction on that type library.

C++ com 组件 事件 备忘的更多相关文章

  1. vux Tabbar组件入门备忘大佬多指点

    一.Tabbar引入及使用 1.新创建vue文件 2.在vue文件中添加插件 <template> <div> <tabbar style="position: ...

  2. 【C#】无损转换Image为Icon 【C#】组件发布:MessageTip,轻快型消息提示窗 【C#】给无窗口的进程发送消息 【手记】WebBrowser响应页面中的blank开新窗口及window.close关闭本窗体 【手记】调用Process.EnterDebugMode引发异常:并非所有引用的特权或组都分配给呼叫方 【C#】DataRowState演变备忘

    [C#]无损转换Image为Icon 如题,市面上常见的方法是: var handle = bmp.GetHicon(); //得到图标句柄 return Icon.FromHandle(handle ...

  3. AngularJS之备忘与诀窍

    译自:<angularjs> 备忘与诀窍 目前为止,之前的章节已经覆盖了Angular所有功能结构中的大多数,包括指令,服务,控制器,资源以及其它内容.但是我们知道有时候仅仅阅读是不够的. ...

  4. Nmap备忘单:从探索到漏洞利用(Part 5)

    这是备忘单的最后一部分,在这里主要讲述漏洞评估和渗透测试. 数据库审计 列出数据库名称 nmap -sV --script=mysql-databases 192.168.195.130 上图并没有显 ...

  5. HTML5终极备忘大全

    二.文字备忘之标签 HTML5中新增的标签 <article> 定义文章 <aside> 定义页面内容旁边的内容 <audio> 定义声音内容 <canvas ...

  6. [转] HTML5终极备忘大全(图片版+文字版)---张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1544 一.前言兼图片 ...

  7. UISearchBar -- 备忘

    搜索功能的备忘 UISearchBar UISearchBar是一个搜索栏,继承自UIView,也是常用的控件之一,所以特别写一篇备忘方便以后做工具文章. 例子: let searchBar = UI ...

  8. Colletion View 简单的备忘

    UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...

  9. Table view 备忘

    Table view 备忘 本篇会以备忘为主,主要是一些基础的代理方法和数据源方法具体的优化好点子会后续跟上. Table view的数据源方法 必须实现的数据源方法 // 返回每一行的cell,可以 ...

随机推荐

  1. 测试 windows 发布日志

    <script>alert("hellow world")</script>

  2. 深入理解JVM线程模型

    1. jvm内存模型在描述jvm线程模型之前,我们先深入的理解下,jvm内存模型.在jvm1.8之前,jvm的逻辑结构和物理结构是对应的.即Jvm在初始化的时候,会为堆(heap),栈(stack), ...

  3. [易学易懂系列|rustlang语言|零基础|快速入门|(7)|函数Functions与闭包Closure]

    [易学易懂系列|rustlang语言|零基础|快速入门|(7)函数Functions与闭包Closure] 有意思的基础知识 函数Functions与闭包Closure 我们今天再来看看函数. 在Ru ...

  4. css不同情况下的各种居中方法

    div水平居中 1.行内元素 .parent{ text-align: center } 2.块级元素 .son{ margin: 0 auto ; } 3.flex布局 .parent{ displ ...

  5. thinkphp类型转换

    类型转换 说白了就是在model类中声明的字段输出类型:其语法如下: 注意strtotime()函数可以将诸如‘2018-12-21’这样的日期字符串转为整数存入数据库 自动完成---等于提前对某一表 ...

  6. DOM操作元素

    DOM 操作元素 JavaScript的DOM操作可以改变网页内容.结构和样式.我们可以利用DOM操作元素来改变元素里面的内容.属性等. DOM操作元素: 一.操作元素:(一)innerText .( ...

  7. CSS自适应布局

    目标效果: 缩小浏览器之后 在<head>最前面引入flexible.js <head> ... <script type="text/javascript&q ...

  8. Codeforces 960D Full Binary Tree Queries ( 思维 && 模拟 )

    题意 : 给出一颗无限层的满二叉树,然后每个值为 X (根的 X 等于 1 ) 左孩子的值是 2*X,右孩子的值是 2*X+1 ,现在有两种操作,(1, x,k) 表示将 x 所在层的所有节点整体向右 ...

  9. Qt第三方库----QCustomPlot

    一.软件下载 下载地址:http://www.qcustomplot.com/index.php/download 这里推荐下载第一个链接的内容: 注:这里的第三方库要放在非中文目录下. 二.配置 ( ...

  10. codevs2833 奇怪的梦境 x

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中 ...