使用哪个COM智能指针类? [英] Which COM smart pointer classes to use?

查看:207
本文介绍了使用哪个COM智能指针类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C ++编程的COM智能指针类的选择感到困惑:

I'm confused by the choices for COM smart pointers classes for C++ programming:

有三个四个我知道:

There's three four I'm aware of:


  • CCOMPtr 来自ATL

  • _com_ptr_t MS Com支持类

  • TComInterface (因为我使用C ++ Builder 2009)

  • CCOMQIPtr (我以前忘记了)

  • CCOMPtr from ATL
  • _com_ptr_t from the MS Com Support Classes
  • TComInterface (because I'm using C++Builder 2009)
  • CCOMQIPtr, (which I'd previously forgotten)

ve读取关于前两个的错误与异常处理差异,但 TComInterface 似乎完全没有记录。前两者似乎都有陷阱或意外的行为,从我可以找到。

I've read about the error vs. exception handling differences of the first two, but TComInterface seems totally undocumented. Both the first two seem to have gotchas or 'unexpected' behaviour, from what I can find.

理想情况下,我想要一个干净,现代的C ++, code> boost :: com 根据我知道不存在...

Ideally, I'd like something that's clean and modern C++, but boost::com doesn't exist as far as I know...

我需要控制一个应用程序另一个供应商。他们通过TLB文件提供一个COM接口。

I need to control an application from another vendor. They provide a COM interface via a TLB file.

推荐答案

如果你使用类库库导入的东西,基于 _com_ptr_t 和相关的COM支持类。

If you are using the type-library import stuff, it will generate code based upon _com_ptr_t and the related COM Support Classes. Go ahead and use those if you are just using stuff from those libraries.

如果您正在编写基于ATL的代码,请使用 CCOMPtr 和其他基于ATL的类。

If you are writing ATL-based code, then use CCOMPtr and the other ATL-based classes.

如果你需要混合和匹配这两种类型,事情可能会变得丑陋,但你应该得到舒适的两个和使用哪一个最适合你正在做的任何事情。

Things may get ugly if you need to mix-and-match both types, but you should probably just get comfortable with both and use whichever makes the most sense for whatever you are doing at the time.

很好的是,你有所有这些东西的源,因此,你不必只依赖于文档(从.NET开始就没有太多的关注)。

The nice thing is that you have the source for all of these things, so you don't have to rely only on the documentation (which has not been getting much care since .NET appeared).

这篇关于使用哪个COM智能指针类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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