Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

_com_ptr_t Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

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.

Construction

_com_ptr_tConstructs a _com_ptr_t object.

Low-Level Operations

AddRefCalls the AddRef member function of IUnknown on the encapsulated interface pointer.
AttachEncapsulates a raw interface pointer of this smart pointer's type.
CreateInstanceCreates a new instance of an object given a CLSID or ProgID.
DetachExtracts and returns the encapsulated interface pointer.
GetActiveObjectAttaches to an existing instance of an object given a CLSID or ProgID.
GetInterfacePtrReturns the encapsulated interface pointer.
QueryInterfaceCalls the QueryInterface member function of IUnknown on the encapsulated interface pointer.
ReleaseCalls the Release member function of IUnknown on the encapsulated interface pointer.

Operators

operator =Assigns a new value to an existing _com_ptr_t object.
operators ==, !=, <, >, <=, >=Compare the smart pointer object to another smart pointer, raw interface pointer, or NULL.
ExtractorsExtract 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)

Compiler COM Support Classes

Show:
© 2017 Microsoft