[
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. puppet工简介一

    puppet简介一 puppet工作原理 puppet 是一个配置管理工具, 典型的, puppet 是一个 C/S 结构, 当然,这里的 C 可以有很多,因 此,也可以说是一个星型结构. 所有的 p ...

  2. Jmeter分布式测试dubbo接口1

    最近工作中接到一个需求,需要对一个Dubbo接口进行压力测试,测试其性能,之前一直使用jmeter做压力测试,在踏了好多坑之后,决定把这些记录下来,顺便也希望能帮助到大家. 开始测试之前,我们需要先知 ...

  3. Ubuntu无法安装nginx

    1.问题Reading package lists... DoneBuilding dependency tree       Reading state information... DoneSom ...

  4. java高并发实战Netty+协程(Fiber)|系列1|事件驱动模式和零拷贝

    今天开始写一些高并发实战系列. 本系列主要讲两大主流框架: Netty和Quasar(java纤程库) 先介绍netty吧,netty是业界比较成熟的高性能异步NIO框架. 简单来说,它就是对NIO2 ...

  5. oracle查询语句执行顺序

    完整的查询语句类似是这样的: select ..., ROWNUM from table where <where clause> group by <columns> hav ...

  6. 工作流学习之入门demo

    /** * Copyright (C), 2015-2018, XXX有限公司 * FileName: DemoMain * Author: happy * Date: 2018/6/23 16:33 ...

  7. Python 时间序列

    Python - 时间处理模块 datetime - 常用模块 官方文档 time calendar

  8. print的位置差异

    第一种,for循环和print是同级的,只有当for循环结束了才会print d=[]for i in range(1, 101): d.append(i)print d[6::7] 第二种,也就是p ...

  9. 如何在生产环境下实现每天自动备份mysql数据库

    1.描述 通"shell脚本+定时任务"的方式来实现自动备份mysql数据库. 2.环境 备份路径:/data/mysqlbak/ 备份脚本:/data/mysqlbak/mysq ...

  10. 基于Ubuntu 搭建 WordPress 个人博客 - 开发者实验室 - 腾讯云

    1.准备 LAMP 环境 安装 Apache2 在终端输入该命令 ,使用 apt-get 安装 Apache2: sudo apt-get install apache2 -y 安装好后,您可以通过访 ...