Posts Tagged ‘CComPtr’

CComPtr vs _com_ptr_t

Recently a user asked this question in forums, I was quite able to answer his query. So thought this might be useful to you guys too. 🙂

So the basic difference is that CComPtr is an ATL class is used with using ATL COM implementations while _com_ptr_t is one of the few COM support classes to support non ATL COM development. The definitions of these COM support classes go along with the tlb files and probably that’s why they are called as COM support classes. Also their definition can be found in comdef.h too. The other classes similar to _com_ptr_t are …

  1. _bstr_t
  2. _com_error
  3. _com_ptr_t
  4. _variant_t

So what are COM support classes? These are special lightweight classes that wraps basic useful COM functionality so that ideas like COM smart pointer typedefs over raw COM inteface classes works just by using tlb file. An example on how _com_ptr_t is used…

_COM_SMARTPTR_TYPEDEF(IMyInterface, __uuidof(IMyInterface));

This above line declares _com_ptr_t specialization IMyInterfacePtr.

The library to link to for using COM support classes is comsuppw.lib.

Categories: C++, VC++, COM Tags: ,
%d bloggers like this: