• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >vc/mfc > 初始化COM类,在FinalConstruct与构造函数中初始化有何区别

初始化COM类,在FinalConstruct与构造函数中初始化有何区别

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-04

佚名通过本文主要向大家介绍了finalconstruct,construct,construct2,@postconstruct,construct是什么意思等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 初始化COM类,在FinalConstruct与构造函数中初始化有何区别
描述:

COM类初始化时问题,在FinalConstruct与构造函数中初始化有何区别,是否如果在构造函数中有成员函数调用必须使用FinalConstruct


解决方案1:

深入解析ATL里这段说的很明白,

解决方案2:

There are advantages to performing initialization in FinalConstruct rather than the constructor of your class: 
   You cannot return a status code from a constructor, but you can return an HRESULT by means of FinalConstruct's return value. When objects of your class are being created using the standard class factory provided by ATL, this return value is propagated back to the COM client allowing you to provide them with detailed error information. 
   You cannot call virtual functions through the virtual function mechanism from the constructor of a class. Calling a virtual function from the constructor of a class results in a statically resolved call to the function as it is defined at that point in the inheritance hierarchy. Calls to pure virtual functions result in linker errors. 
   Your class is not the most derived class in the inheritance hierarchy — it relies on a derived class supplied by ATL to provide some of its functionality. There is a good chance that your initialization will need to use the features provided by that class (this is certainly true when objects of your class need to aggregate other objects), but the constructor in your class has no way to access those features. The construction code for your class is executed before the most derived class is fully constructed. 
However, FinalConstruct is called immediately after the most derived class is fully constructed allowing you to call virtual functions and use the reference-counting implementation provided by ATL. 
----From MSDN

解决方案3:

up


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 为什么要重载ATL类的FinalConstruct?在这个函数里面我们通常做什么事情?
  • 什么情况下需要修改FinalConstruct/FinalRelease的代码?
  • 初始化COM类,在FinalConstruct与构造函数中初始化有何区别

相关文章

  • 2017-06-04 为什么我在非模态框中显示ToolTips不行?
  • 2017-06-04 关于DISPID_ONADDRESSBAR
  • 2017-06-04 请问ATL写COM的问题.
  • 2017-06-05 dll代码调试之后出现下述出错信息,不知道是什么意思,还请高手大侠们为我诊断一下,谢谢!
  • 2017-06-05 奇怪的函数里的变量,我相信很多初学者肯定碰到过,大家一定要进来看看?
  • 2017-06-04 MFC编写的ActiveX如何能嵌入到IE里
  • 2017-06-04 如何通过InstallShield打包自写的DLL,并请DLL在安装程序运行过程中自动进行注册。
  • 2017-06-05 com要和net互操作传递一个数组,应该传递什么类型的数据?
  • 2017-06-05 DBGrid控件如何去掉系统提示信息
  • 2017-06-05 怎么样阻止一个EXE文件的运行,最好有例子

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • DLL中函数之间指针传递的问题
    • 递归开线程疑问
    • !!!!控制台程序开了几个线程,怎么在main结束前,让各个线程释放了资源再退出?我怎么知道用户要关闭控制台程序?
    • 看看这句话什么意思
    • 我想像使用Heap那样使用共享内存,有没有什么现成的方法啊?是否必须自己编代码?
    • 如何在dll中响应消息
    • 怎么样才在系统进程中找到一个程序是不是在运行~
    • activexcontroltestcontainer调试时,如何传对象参数?
    • 求助VBA,翻译成VC。语句为:ActiveSheetShapes"Line1"Select
    • 一个关于DLL的问题

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有