The latest version of this topic can be found at _com_ptr_t Class.
_com_ptr_t object encapsulates a COM interface pointer and is called a "smart" pointer. This template class manages resource allocation and deallocation through function calls to the IUnknown member functions:
AddRef, and Release.
A smart pointer is usually referenced by the typedef definition provided by the _COM_SMARTPTR_TYPEDEF macro. This macro takes an interface name and the IID and declares a specialization of
_com_ptr_t with the name of the interface plus a suffix of
Ptr. For example:
_com_ptr_t specialization IMyInterfacePtr.
A set of function templates, not members of this template class, support comparisons with a smart pointer on the right side of the comparison operator.
|Attach||Encapsulates a raw interface pointer of this smart pointer's type.|
|CreateInstance||Creates a new instance of an object given a CLSID or ProgID.|
|Detach||Extracts and returns the encapsulated interface pointer.|
|GetActiveObject||Attaches to an existing instance of an object given a CLSID or ProgID.|
|GetInterfacePtr||Returns the encapsulated interface pointer.|
|Release||Calls the Release member function of IUnknown on the encapsulated interface pointer.|
|operator =||Assigns a new value to an existing
|operators ==, !=, <, >, <=, >=||Compare the smart pointer object to another smart pointer, raw interface pointer, or NULL.|
|Extractors||Extract the encapsulated COM interface pointer.|
END Microsoft Specific
Lib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)