每个新的COM类必须重新实现IUnknown接口吗? [英] Must the IUnknown interface be re-implemented by every new COM class?

查看:232
本文介绍了每个新的COM类必须重新实现IUnknown接口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果这个问题对每个人都显而易见,但我是COM的新人。从教程中我看到 http://www.codeguru .com / cpp / com-tech / activex / tutorials / article.php / c5567 ,似乎在C ++中创建的每个COM类都必须实现自己的QueryInterface,AddRef和Release。因为这些方法应该对任何新类基本上具有相同的实现,我不明白为什么没有一些抽象类或任何实现它的开发人员。我不明白为什么我应该重新实现那么多人已经实施一样的东西(除非教程是错误的,有什么)。



感谢

解决方案

FTA:


我相信每个希望了解COM背后的基本原理的程序员必须使用纯C ++编写至少一个简单的COM对象,即不需要借助MFC / ATL附带的模板和宏。

$为了回答你的问题:是的,每个COM组件必须实现 IUnknown ,它是基于COM的基础。然而,对于创建COM对象的标准pluming,这是 ATL项目向导用于。


Sorry if this question seems obvious for everyone, but I am very new to COM. From the tutorial I see here http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567, it seems like every COM class created in C++ must implement its own QueryInterface, AddRef and Release. Since these methods should have basically the same implementation for any new class, I don't understand why there isn't some abstract class or whatever that implements it for the developer. I don't understand why I should re-implement the same thing that so many people have already implemented again and again (unless the tutorial is wrong and there IS something).

Thanks

解决方案

FTA:

"I believe that every programmer who wishes to understand the basic principles behind COM, must write atleast one simple COM object using plain C++ , i.e. without the aid of templates and macros that comes along with MFC/ATL."

To answer your question: Yes, every COM component must implement IUnknown, it's the foundation COM is built on. However, as for the "standard pluming" for creating COM objects this is what the ATL Project Wizard is for.

这篇关于每个新的COM类必须重新实现IUnknown接口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆