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引言面对计算机图书市场的繁荣景象,我经常感叹今天学习计算机开发技术的同道们是多么幸运。十年前,我们学习计算机语言非常不容易,要掌握各

2005

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 嵌入

Windows11上CUDA 12.3配PyTorch踩坑记:一条官网命令救了我的GPU加速

本文详细介绍了在Windows 11上配置CUDA 12.3与PyTorch的完整指南,包括环境准备、安装要点、兼容性解决方案和性能验证。通过官方推荐的conda命令和实用技巧,帮助开发者解决常见问题,实现高效的GPU加速,提升深度学习开发效率。

weixin_42528974的博客 109

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

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

massice的专栏 1247

告别瞎猜!用通达信L2资金流向函数,手把手教你识别主力动向(附实战公式)

本文详细解析通达信L2资金流向函数,手把手教你构建主力动向监控系统。通过分档数据解析、委买委卖攻防解读及实战公式应用,帮助投资者精准识别主力建仓与虚假拉升信号,提升股票交易决策效率。

weixin_26908317的博客 2091

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

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

RedStar81的专栏 2867

Mac Studio M5 Ultra本地部署大模型实战:从内存原理到Ollama开发工作流

大模型推理的性能瓶颈往往不在算力,而在于内存能否装下整个模型、带宽能否持续供得上。Transformer架构每生成一个token都需要把权重完整扫一遍,决定了这本质上是内存密集型任务——统一内存架构因此成为本地部署的关键通路,超大容量与高带宽并行,让“装得下”和“跑得快”同时成立。模型量化技术(如Q4_K_M)则是另一项决定性软件策略,用轻微精度损失换取更低的硬件门槛,也是Ollama本地部署从7B到70B各类模型必做的前置功课。当本地推理服务跑起来后,借助VS Code等开发工具的OpenAI兼容API接

weixin_29043895的博客 453

储能系统架构和控制

探讨了储能系统中EMS(能源管理系统)、BMS(电池管理系统)和PCS(功率转换系统)之间的协同机制,以及组串式和集中式储能系统的技术架构、优势和局限性。EMS根据电价、电网需求和电池状态制定充放电策略,BMS提供电池数据,PCS执行充放电控制。组串式系统具有独立管理和灵活扩展的优势,但成本较高;集中式系统成本效益高,但存在环流和木桶效应问题。

蓝龙宝藏的博客 3969

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

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

1544

从Mule ESB到Apache Camel:手把手教你设计一个轻量级企业集成框架的‘心脏’

本文深入探讨了从Mule ESB到Apache Camel的轻量级企业集成框架设计实践,对比了两者在协议支持、消息处理能力和部署灵活性等方面的差异。通过实际代码示例和性能优化技巧,帮助开发者构建高效的核心模块,适用于现代微服务架构下的系统集成需求。

weixin_28738165的博客 375

推荐一本学习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 --...

测试 174

基于传统算法的半导体晶圆缺陷检测原理及代码(二)

了解基于传统算法的半导体晶圆缺陷检测原理和方法,对于深入理解半导体制造工艺和质量控制具有重要意义。在半导体制造技术持续创新的浪潮中,基于传统算法的缺陷检测技术也将不断演进,为半导体产业的高质量发展提供坚实可靠的技术支撑,确保在芯片制造的每一个环节都能精准识别和管控缺陷,推动半导体产业迈向更高的发展水平。基于传统算法的半导体晶圆缺陷检测技术在半导体制造的长期发展历程中扮演了重要角色,凭借其成熟的技术体系、较快的检测速度和相对较低的成本,在各个工艺阶段为保障晶圆质量发挥了关键作用。

m0_44975814的博客 2220

[QMT量化交易小白入门]-九、如何用Python记录每一笔交易和调试,报错信息?

定义一个函数来获取日志记录器。: 返回全局的日志记录器,以便在其他地方调用。

木头大左的博客 2144

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

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

cg2004ren的专栏 652

Xilinx差分原语-IBUFGDS与OBUFGDS FPGA

它将差分信号转换为单端信号,并将其输入到FPGA的逻辑片上。它将单端信号转换为差分信号,并将其输出到FPGA的引脚。在FPGA设计中,差分信号是一种常见的信号传输方式,用于提高抗噪性和抑制共模噪声。Xilinx是一家知名的FPGA供应商,提供了许多差分原语,其中包括IBUFGDS和OBUFGDS。通过使用Xilinx的差分原语,如IBUFGDS和OBUFGDS,可以实现差分信号的输入和输出。这些差分原语提供了方便且可靠的接口,使得在FPGA设计中处理差分信号变得更加简单和高效。是差分输入信号的端口,

git_database727的博客 2096

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

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

mcmcmc的专栏 592

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

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

TopMVP 1171

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

《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的专栏 851

ATL Internals 2ed复习.chapter 4.Creators

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

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值