_com_ptr_t Class
Microsoft Specific
A _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: QueryInterface, 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_SMARTPTR_TYPEDEF(IMyInterface, __uuidof(IMyInterface));
declares the _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.
| Constructs a _com_ptr_t object. |
| Calls the AddRef member function of IUnknown on the encapsulated interface pointer. | |
| Encapsulates a raw interface pointer of this smart pointer's type. | |
| Creates a new instance of an object given a CLSID or ProgID. | |
| Extracts and returns the encapsulated interface pointer. | |
| Attaches to an existing instance of an object given a CLSID or ProgID. | |
| Returns the encapsulated interface pointer. | |
| Calls the QueryInterface member function of IUnknown on the encapsulated interface pointer. | |
| Calls the Release member function of IUnknown on the encapsulated interface pointer. |
| Assigns a new value to an existing _com_ptr_t object. | |
| Compare the smart pointer object to another smart pointer, raw interface pointer, or NULL. | |
| Extract the encapsulated COM interface pointer. |
Header: comip.h
Lib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)
To use this handy class, and the other Compiler COM Support Classes, in the WDK, you have to link with vccomsup.lib (not comsuppw.lib or comsuppwd.lib). Just add $(SDK_LIB_PATH)\vccomsup.lib to the TARGETLIBS in your sources file.
This results in the build giving an error:
error BLD1001 : vccomsup.lib listed explicitly - use USE_VCCOM=1
but it still successfully builds the executable. Adding USE_VCCOM=1 to the sources file has no effect, the error is still produced.