C++ com 组件 事件 备忘
[
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 组件 事件 备忘的更多相关文章
- vux Tabbar组件入门备忘大佬多指点
一.Tabbar引入及使用 1.新创建vue文件 2.在vue文件中添加插件 <template> <div> <tabbar style="position: ...
- 【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 ...
- AngularJS之备忘与诀窍
译自:<angularjs> 备忘与诀窍 目前为止,之前的章节已经覆盖了Angular所有功能结构中的大多数,包括指令,服务,控制器,资源以及其它内容.但是我们知道有时候仅仅阅读是不够的. ...
- Nmap备忘单:从探索到漏洞利用(Part 5)
这是备忘单的最后一部分,在这里主要讲述漏洞评估和渗透测试. 数据库审计 列出数据库名称 nmap -sV --script=mysql-databases 192.168.195.130 上图并没有显 ...
- HTML5终极备忘大全
二.文字备忘之标签 HTML5中新增的标签 <article> 定义文章 <aside> 定义页面内容旁边的内容 <audio> 定义声音内容 <canvas ...
- [转] HTML5终极备忘大全(图片版+文字版)---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1544 一.前言兼图片 ...
- UISearchBar -- 备忘
搜索功能的备忘 UISearchBar UISearchBar是一个搜索栏,继承自UIView,也是常用的控件之一,所以特别写一篇备忘方便以后做工具文章. 例子: let searchBar = UI ...
- Colletion View 简单的备忘
UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...
- Table view 备忘
Table view 备忘 本篇会以备忘为主,主要是一些基础的代理方法和数据源方法具体的优化好点子会后续跟上. Table view的数据源方法 必须实现的数据源方法 // 返回每一行的cell,可以 ...
随机推荐
- zabbix 添加图行树
1.安装graphtree cd /usr/share/zabbix wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/ ...
- QByteArray与QString的互相转换
QByteArray baData; QString str = QString(baData); // 反过来转换: QByteArray by1 = str.toLatin1(); QByteAr ...
- C# 判断 List 是否存在某一个字段
foreach (var item in list_QuestionnaireSelect) { EntityQuestionnaireParticipantsReport _entityReport ...
- Redis(一)
1 单机MySQL的美好时代2 Memcached(缓存)+MySQL+垂直拆分3 MySQL主从读写分离4 分库分表+水平拆分+mysql拆分5 MySQL的扩展瓶颈6 为什么使用NoSQLNoSQ ...
- layui 源码解读(部分)
<!DOCTYPE html> <head> </head> <body> <input type="button" id=& ...
- C#内存占用释放
序言 系统启动起来以后,内存占用越来越大,使用析构函数.GC.Collect什么的也不见效果,后来查了好久,找到了个办法,就是使用 SetProcessWorkingSetSize函数.这个函数是Wi ...
- C++STL中的unique函数
头文件:#include<iostream> 函数原型:iterator unique(iterator it_1,iterator it_2); 作用:元素去重,即”删除”序列中所有相邻 ...
- Linux下cs简单通讯(socket)
Server: #include<iostream> #include<sys/types.h> #include<sys/socket.h> #include&l ...
- _vimrc
set nocompatible source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin set ...
- Selenium-webdriver+八种元素定位
进行Web页面自动化测试,对页面上的元素进行定位和操作是核心.而操作又是以定位为前提的,因此,对页面元素的定位是进行自动化测试的基础. 页面上的元素就像人一样,有各种属性,比如元素名字,元素id,元素 ...