[
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. kubernets全套笔记

    Master/node Master核心组件: API server,Scheduler,Controller-Manager  etcd(存储组件) Node核心组件:  kubelet(核心组件) ...

  2. 【CF461B】Appleman and Tree

    题目大意:给定一棵 N 个节点的有根树,1 号节点为根节点,每个点有两种颜色(黑.白),现给出树上每个节点的颜色,求有多少种分割树的方式,使得分割出的每个联通块中有且仅有一个黑点. 题解:树形dp 由 ...

  3. DevExpress WinForms v19.1新版亮点:Spreadsheet/Sunburst控件功能增强

    行业领先的.NET界面控件DevExpress v19.1终于正式发布,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WinForms v19.1中新增的一些控 ...

  4. mysql8.0.16操作记录

    mysql8.0.16操作记录 2.1.登录 -uroot -p'AnvcTMagdLarwNV3CKaC' mysql: [Warning] Using a password on the comm ...

  5. Shell-07数组与字符串

    Shell-07数组与字符串 数组 数组说白了就是一段连续的变量,一段连续的内存存储空间 解决:变量过多的问题:在同类的变量中,我们不需要去定义多个名字,而是以数组的方式来定义:(列表) 数组名 索引 ...

  6. PHP技术分享-起始时间戳和结束时间戳的方法

    php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面兄弟连PHP培训 首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日 ...

  7. ExcelUtils

    本ExcelUtils工具类是用poi写的,仅用于线下从excel文件中读取数据.如果生产环境要用的话,建议切换到阿里的easyexcel. 引入poi.jar: <!-- https://mv ...

  8. 洛谷 P1505 BZOJ 2157 [国家集训队]旅游

    bzoj题面 Time limit 10000 ms Memory limit 265216 kB OS Linux 吐槽 又浪费一个下午--区间乘-1之后,最大值和最小值更新有坑.新的最大值是原来最 ...

  9. Xshell Linux常用命令

    Xshell :一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议. 0 帮助 命令 与清屏 help  查看帮助命令 ls  ...

  10. cin.clear()、cin.sync()

    看机器学习时,发现之前学的C++代码忘了,cin.clear().cin.sync() cin.clear():将流中的所有状态值都重设为有效值 cin.sync():清空流 这个很有意思,如果没有c ...