ATL Internals 笔记

ATL Internals 源代码学习指南 本文还有配套的精品资源,点击获取 简介:《ATL Internals》是一本深入剖析微软Active Template Library(ATL)的书籍,它详细讲解了ATL的核心概念、设计模式及技术细节,并配以示例源代码以增强学习体验。ATL是一个轻量级的C++库,专门用于创建高效的COM对象,提供了丰富的模板类和宏以简化COM接口的实现。本书涵盖COM基础、类工厂、简单对象... 阅读详情

书要慢慢读, 饭要慢慢吃.急什么? 越急越慢, 再急熄火...

 关于套间的一段描述:

The Options page is your chance to make some lower-level COM decisions. The Threading model setting describes the kind of apartment where you want instances of this new class to live: a single-threaded apartment (STA, also known as the Apartment model), or a multithreaded apartment (MTA, also known as the Free-Threaded model). The Single model is for the rare class that requires all its objects to share the application's main STA, regardless of the client's apartment type. The Both model is for objects that you want to live in the same apartment as their clients, to avoid the overhead of a proxy/stub pair. The Neutral threading model is available only on Windows 2000 (and later) and is useful for objects that can safely execute on the thread of the caller. Calls to components marked as Neutral often execute more quickly because a thread switch is not required, whereas a thread switch always occurs with cross-apartment calls between other types of apartments. The Threading model setting that you choose determines the value for the ThreadingModel named value placed in the Registry for your server; it determines just how thread safe you need your object's implementation of AddRef and Release to be.

 

 

有一个问题:

Inserting a COM Class

Adding an ATL Simple Object

When you have an ATL COM server, you'll probably want to insert a new COM class. This is accomplished by selecting the Add Class item in the Project menu. When inserting an ATL class, you first have to choose the type of class you want, as shown in Figure 1.4.

 

Figure 1.4. Adding an ATL COM class

 

 

 


If you're following along, you might want to take a moment to explore the various types of classes available. Each of these classes results in a specific set of code being generated, using the ATL base classes to provide most of the functionality and then generating the skeleton for your own custom functionality. The wizard for a particular class type is your chance to decide which interfaces you want your COM class to implement. Unfortunately, the wizard doesn't provide access to all the functionality of ATL (or even most of it), but the generated code is designed to be easy for you to add or subtract functionality after it has gotten you started. Experimentation is the best way to get familiar with the various wizard-generated class types and their options.

After you choose one of the class types (and press OK), Visual Studio generally asks for some specific information from you. Some of the classes have more options than the ATL Simple Object (as selected in Figure 1.4), but most of the COM classes require at least the information shown in Figures 1.5 and 1.6.[3]

[3] I should note that the ATL team got the terminology wrong here. The ATL Simple Object Wizard inserts a "class," not an "object."

 

Figure 1.5. Setting COM class names

 

 

 


 

Figure 1.6. Setting COM class attributes

 

 

 


The Names tab of the ATL Simple Object Wizard dialog box requires you to type in only the short name, such as CalcPi. This short name is used to compose the rest of the information in this dialog box (which you can override, if you choose). The information is divided into two categories. The necessary C++ information is the name of the C++ class and the names of the header and implementation files. The necessary COM information is the coclass name (for the Interface Definition Language [IDL]); the name of the default interface (also for the IDL); the friendly name, called the Type (for the IDL and the registration settings); and finally the version-independent programmatic identifier (for the registration settings). The versioned ProgID is just the version-independent ProgID with the ".1" suffix. Note that the Attributed option is not selected. In a nonattributed project, we have the option of selectively adding attributed classes to our project via the Attributed check box in Figure 1.5.

The Options page is your chance to make some lower-level COM decisions. The Threading model setting describes the kind of apartment where you want instances of this new class to live: a single-threaded apartment (STA, also known as the Apartment model), or a multithreaded apartment (MTA, also known as the Free-Threaded model). The Single model is for the rare class that requires all its objects to share the application's main STA, regardless of the client's apartment type. The Both model is for objects that you want to live in the same apartment as their clients, to avoid the overhead of a proxy/stub pair. The Neutral threading model is available only on Windows 2000 (and later) and is useful for objects that can safely execute on the thread of the caller. Calls to components marked as Neutral often execute more quickly because a thread switch is not required, whereas a thread switch always occurs with cross-apartment calls between other types of apartments. The Threading model setting that you choose determines the value for the ThreadingModel named value placed in the Registry for your server; it determines just how thread safe you need your object's implementation of AddRef and Release to be.

The Interface setting enables you to determine the kind of interface you want the class's default interface to be: Custom (it needs a custom proxy/stub and does not derive from IDispatch) or Dual (it uses the type library marshaler and derives from IDispatch). This setting determines how the IDL that defines your default interface is generated. Custom interfaces can further be qualified by selecting the Automation Compatible option. This option adorns the IDL interface definition with the [oleautomation] attribute, which restricts the variable types that your interface's methods can use to OLE Automation-compatible types. For instance, [oleautomation] interface methods must use the SAFEARRAY type instead of conventional C-style arrays. If you plan to use your ATL COM object from several different client environments, such as Visual Basic, it is a good idea to check this option. Moreover, accessing COM objects from code running in the Microsoft .NET framework is much simpler if [oleautomation] interfaces are used. Deploying your COM object might also be simpler with the use of [oleautomation] interfaces because these interfaces always use the universal marshaler to pass interface references across apartments. The type library marshaler always is present on a machine that supports COM, so you don't need to distribute a proxy/stub DLL with your component.

The Aggregation setting enables you to determine whether you want your objects to be aggregatablethat is, whether to participate in aggregation as the controlled inner. This setting does not affect whether objects of your new class can use aggregation as the controlling outer. See Chapter 4, "Objects in ATL," for more details about being aggregated, and Chapter 6, "Interface Maps," about aggregating other objects.

The Support ISupportErrorInfo setting directs the wizard to generate an implementation of ISupportErrorInfo. This is necessary if you want to throw COM exceptions. COM exceptions (also called COM Error Information objects) enable you to pass more detailed error information across languages and apartment boundaries than can be provided with an HRESULT alone. See Chapter 5, "COM Servers," for more information about raising and catching COM exceptions.

The Support Connection Points setting directs the wizard to generate an implementation of IConnectionPoint, which allows your object to fire events into scripting environments such as those hosted by Internet Explorer. Controls also use connection points to fire events into control containers, as discussed in Chapter 9, "Connection Points."

The Help information for the Free-Threaded Marshaler setting reads as follows: "Allows clients in the same interface to get a raw interface even if their threading model doesn't match." This description doesn't begin to describe how dangerous it is for you to choose it. Unfortunately, the Free Threaded Marshaler (FTM) is like an expensive car: If you have to ask, you can't afford it. See Chapter 6, "Interface Maps," for a description of the FTM before checking this box.

The Support IObjectWithSite setting directs the wizard to generate an implementation of IObjectWithSite. Objects being hosted inside containers such as Internet Explorer use this interface. Containers use this interface to pass interface pointers to the objects they host so that these objects can directly communicate with their container.

Results of the ATL Simple Object Wizard

After you specify the options, the Simple Object Wizard generates the skeleton files for you to start adding your implementation. For the class, there is a newly generated header file containing the class definition, a .cpp file for the implementation, and an .RGS file containing registration information.[4] In addition, the IDL file is updated to contain the new interface definition.

[4] See Chapters 4 and 5 for more information on COM class registration.

The generated class definition looks like this:


class ATL_NO_VTABLE CCalcPi :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CCalcPi, &CLSID_CalcPi>,
    public ISupportErrorInfo,
    public IConnectionPointContainerImpl<CCalcPi>,
    public CProxy_ICalcPiEvents<CCalcPi>,
    public IDispatchImpl<ICalcPi, &IID_ICalcPi, &LIBID_PiSvrLib,

The first thing to notice is the list of base classes. In this instance, ATL takes advantage of both templates and multiple inheritance. Each base class provides a separate piece of the common code needed for a COM object:

  • CComObjectRootEx provides the implementation of the IUnknown interface.

  • CComCoClass provides the class factory implementation.

当初学习COM的时候, 说COM不支持继承, 具体的说是不支持实现继承, 但这里的class CCalcPi : public CComObjectRootEx

不是实现继承吗?

 

进度: Adding Properties and Methods.

ATL.Internals.8.2nd ATL.Internals.Working.with.ATL.8.2nd.Edition.Jul.2006 PDF Document 立即下载

相关推荐

深入解析ATL(第2版)ATL Internals: Working with ATL 8 (2nd Edition)

中文版 清晰 pdf,经典ATL又一升级力作,不容错过。 这是第一部分。因为不能大于60M,所以只能分开为2部分了。 原书名: ATL Internals: Working with ATL 8 (2nd Edition) 作者: (美)Chris Tavares Kirk Fertitta Brent Rector Chris Sells

《ATL Internals》书评 . 潘爱民

潘爱民 提供 2000/06/12 未经作者允许任何机构或个人不得以任何方式转载或复制本文ATL之深入浅出介绍一本关于ATL的书《ATL Internals》潘爱民,5月7日,2000年北京大学计算机研究所,100871引言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各

2009

ATL Internals

The source code of ATL Internals

深入解析ATL (ATL Internals) 第1版+第2版 高清PDF下载

深入解析ATL (ATL Internals) 潘爱民译 深入解析ATL(第2版)中文版 ATL Internals, 2nd Edition Working with ATL 8 转载于:https://www.cnblogs.com/gavinhughhu/archive/2010/11/12/1875348.html...

weixin_30526593的博客 491

ATLInternals

ATLInternals 嵌入

硬件压力测试工具使用方法

B, --bind host# 绑定到主机的多个地址中的一个。当客户端到服务器端的测试结束时,服务器端通过-l选项指定的端口(或默认为客户端连接到服务器端的端口),反向连接至客户端。-c, --client host#如果Iperf运行在服务器模式,并且用-c参数指定一个主机,那么Iperf将只接受指定主机的连接。-C, --compatibility# 与低版本的Iperf使用时,可以使用兼容模式。-b, --bandwidth #[KM] UDP模式使用的带宽,单位bits/sec。

weixin_53303772的博客 8261

潘爱民::介绍一本关于ATL的书《ATL Internals》 ----转

面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各种开发工具只有靠自己的摸索和极少量的参考手册。我记得,94年我学习Visual C++和MFC的时候,基本上只有靠软件自带的联机帮助;现在情形大不同了,书店中的计算机图书琳琅满目,关于Visual C++和MFC的书籍尤其多。有几位编辑朋友劝我写一点这方面的书,我觉得不大有必要了,因为Visual C++的好书已经不少了,适合各种读者层次的书籍几乎都可以买到,而且有一些书还相当不错

massice的专栏 1248

AI时代,程序员何去何从?别慌,看完这篇你就明白了

AI时代程序员的发展方向 摘要:随着AI代码助手的普及,程序员行业面临变革。本文通过实际案例展示AI写代码的能力与局限:AI能生成基础功能代码(如RESTful API、数据处理脚本),但缺乏业务理解、系统设计和复杂逻辑处理能力。程序员的核心价值在于需求分析、架构设计、性能优化等高层能力。未来程序员应: 掌握AI工具提升效率 专注于创新和架构设计 培养业务理解能力 持续学习新技术 AI不会取代程序员,但会淘汰不会使用AI的程序员。建议开发者拥抱AI工具,将其作为助手而非威胁,聚焦高价值工作。

yunque_xianguang的博客 918

ATL之深入浅出书评(潘爱民)

ATL之深入浅出介绍一本关于ATL的书《ATL Internals》潘爱民,5月7日,2000年北京大学计算机研究所,100871引言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各种开发工具只有靠自己的摸索和极少量的参考手册。我记得,94年我学习Visual C++和MFC的时候,基本上只有靠

RedStar81的专栏 2871

容器内存黑洞排查手册:当PageCache让你的Pod莫名被OOM时

本文深入剖析了容器环境中因Linux内核PageCache机制导致Pod被OOM Killer终止的“内存黑洞”问题。文章解释了Kubernetes基于Working Set内存指标进行OOM判断的逻辑,揭示了传统监控工具与cgroup统计的差异,并通过典型场景分析、实战诊断工具和优化策略,提供了从问题定位到系统调优的完整解决方案。

weixin_29294975的博客 233

全志 T527_Android13 编译 [ 避坑必看 ]

Swap 概念: Linux中Swap(即:交换分区),类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,从而解决内存容量不足的情况。它的功能就是在内存不够的情况下,操作系统先把内存中暂时不用的数据,存到硬盘的交换空间,腾出内存来让别的程序运行。当输入编译命令make -j16 的时候,会有如下提示,这是官方建议通过减少编译线程来解决编译时消耗内存过大的问题。Android 13 系统的编译流程,编译一共分为两部分:内核编译与 Android 编译。

公众号:嵌入式分享 2121

潘爱民::介绍一本关于ATL的书《ATL Internals》

言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各种开发工具只有靠自己的摸索和极少量的参考手册。我记得,94年我学习Visual C++和MFC的时候,基本上只有靠软件自带的联机帮助;现在情形大不同了,书店中的计算机图书琳琅满目,关于Visual C++和MFC的书籍尤其多。有几位编辑朋友劝我写一点这方面的书,我觉

1545

FPGA中的CMAC硬核与Interlaken硬核

CMAC硬核和Interlaken硬核是FPGA中两种重要的内置功能模块,它们分别在CNN推理和高带宽芯片到芯片接口方面发挥着关键作用。FPGA(Field Programmable Gate Array,现场可编程逻辑门阵列)中的CMAC硬核与Interlaken硬核是两种重要的内置功能模块,它们在FPGA设计中扮演着关键角色。需要注意的是,FPGA设计中的硬核选择不仅取决于硬核本身的性能,还需要考虑硬核与FPGA芯片其他部分的兼容性、功耗、成本等因素。Interlaken硬核。

weixin_41230430的博客 1500

推荐一本学习atl的好书 ATL Internals: Working with ATL 8 (2nd Edition) 含有配套源码

ATL Internals: Working with ATL 8 (2nd Edition)," The Table of ContentsForeword Preface Chapter 01 -- Hello ATL Chapter 02 -- Strings and Text Chapter 03 -- Smart Types Chapter 04 --...

测试 177

11.8华为OD机试真题 新系统 - 订单配送路径规划 (Java/Py/C/C++/Js/Go)

11.8华为OD机试真题 新系统 - 订单配送路径规划 (Java/Py/C/C++/Js/Go)

算法大师! 292

1 初识智能化测试

非常感谢您可以和我一起来聊一聊智能化测试的一些事。智能化测试是一个新鲜又老旧的问题,说新鲜是因为很多人当听到智能化测试都会联想到人工智能、机器学习、深度学习等高大上的技术,很多时候觉得离我们的实际工作还很远;说老旧,是因为智能化测试的一些技术的发展在行业里面已经很久了,例如符号执行、静态分析等技术已经有很长的历史了。近些年,随着测试技术的的飞速发展,智能化测试也有了越来越多的实践,优秀的开源项目慢慢的被行业推行并且落地。那么在这里我们就一起来聊聊智能化测试以及智能化测试好的思路、实践、方法以及技术落地过程。

Criss@陈磊 2633

《ATL Internals》书评 . 潘爱民(转)

ATL之深入浅出介绍一本关于ATL的书《ATL Internals》 潘爱民,5月7日,2000年北京大学计算机研究所,100871引言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各种开发工具只有靠自己的摸索和极少量的参考手册。我记得,94年我学习Visual C++和MFC的时候,基本上只有

cg2004ren的专栏 654

后仿真中《SDF反标必懂连载篇》之 <INTERCONNECT/IOPATH> 到底反标电路路径是哪里

对于SDF INTERCONNECT ENTRY 描述,我们在之前的文章有详解。读万卷书,行万里路。实践很重要。今天,搞一下SDF INTERCONNECT / IOPATH 延迟数据信息,究竟反标的是哪一路径延时?究竟在电路上一段段如何表现出延迟现象的呢?

那么菜的博客 2160

ATL Internals 2ed复习.chapter 6.Table driven QueryInterface

The Raw Interface Map ATL实现QueryInterface的方法是调用CComObjectRootBase::InternalQueryInterface(): static HRESULT WINAPI CComObjectRootBase::InternalQueryInterf

mcmcmc的专栏 592

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

ATL Internals: Working with ATL 8 (2nd Edition) DOWNLOAD

ATL Internals: Working with ATL 8 (2nd Edition) Four leading Windows programming experts systematically reveal ATL’s inner workings, explaining not just how ATL works, but why it works the way it

我编程,我快乐 3121

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

ATL Internals: Working with ATL 8 (2nd Edition)

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/topmvp - topmvpFour leading Windows programming experts systematically reveal ATLs inner workings, explaining not just how A

TopMVP 1171

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

《ATL Internals》书评  作者 潘爱民

关键字 ATL 原作者姓名 潘爱民文章原始出处 http://www.vchelp.net/ 正文《ATL Internals》书评 潘爱民 提供 2000/06/12 ATL之深入浅出介绍一本关于ATL的书《ATL Internals》潘爱民,5月7日,2000年北京大学计算机研究所,100871引言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学

1068

ATL Internals 2ed复习.chapter 5.CAtlModule

The _AtlModule Global Variable 每一个项目,wizard都会生成一个全局变量_AtlModule,用户可以通过全局指针_pAtlModule来访问它,例如: class CMathModule : public CAtlDllModuleT { public: DECLARE_LIBID(LIBID_Math) DECLARE_REGIS

mcmcmc的专栏 903

ATL Internals 2ed复习.chapter 5.Object Map

由于有3种COM Server,ATL提供了CAtlModule的派生类对应 CAtlDllModuleT:in-process dll CAtlExeModuleT:out-process exe CAtlServiceModuleT:system service exe   CAtlModule使用了Object Map管理server中所有的类 CAtlModule的职责 找到

mcmcmc的专栏 852

ATL Internals 2ed复习.chapter 4.Creators

由于CreateInstance过程中需要调用FinalConstruct,用户很容易忘记,所以ATL提供了Creator类,这些类提供了一个静态函数 static HRESULT WINAPI CreateInstance(void* pv, REFIID riid, LPVOID* ppv); CComCreator template

mcmcmc的专栏 581
上一篇: 在vc中使用组件的两种方法
下一篇: 重温MFC.
keepdoingit
博客等级 码龄17年 27粉丝 63原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址