[
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. psu补丁

    1.查看命令 su - oracle opatch lspatches su - grid opatch lspatches

  2. vue修改富文本中的元素样式

    富文本编辑器目前应用很广泛,而有时候我们想要对其中的一些元素的样式进行修改,就会遇到问题. 首先,直接修改是不可行的,因为是用v-html标签进行渲染的,无法直接获取到. 在修改的时候,一般是按标签进 ...

  3. php 各种扩展 - 都有

    https://windows.php.net/downloads/pecl/releases/

  4. 【writeup】is_numeric函数矛盾运用

    最近在BugkuCTF平台刷题,遇到‘矛盾’http://120.24.86.145:8002/get/index1.php,感觉蛮有意思的,记录下思路 目标代码如下: $num=$_GET['num ...

  5. creat-react-app生成的项目默认端口号是3000,如何更改?

    从项目的 package.json 文件中可以看到,npm start即scripts start.js,因此我们找到scripts/start.js ,部分代码如下: 找到 DEFAULT_PORT ...

  6. redis分布式锁原理与实现

    分布式锁原理 分布式锁,是控制分布式系统之间同步访问共享资源的一种方式.在分布式系统中,常常需要协调他们的动作.如果不同的系统或是同一个系统的不同主机之间共享了一个或一组资源,那么访问这些资源的时候, ...

  7. Python 时间序列

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

  8. Android图片优化指南

    图片作为内存消耗大户,一直是开发人员尝试优化的重点对象.Bitmap的内存从3.0以前的位于native,到后来改成jvm,再到8.0又改回到native.fresco花费很多精力在5.0系统之前把B ...

  9. TTTTTTTTTTTTTTTTTT POJ 1330

    题意:给一个有根树,一个查询节点(u,v)的最近公共祖先: #include <iostream> #include <cstdio> #include <cstring ...

  10. python中pip相关命令

    用pip安装第三方包的命令 pip install xxx --user 用pip更新第三方包 pip install --upgrade xxx --user 用pip卸载第三方包 pip unin ...