ComPtr Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at ComPtr Class.

Creates a smart pointer type that represents the interface specified by the template parameter. ComPtr automatically maintains a reference count for the underlying interface pointer and releases the interface when the reference count goes to zero.

template <  
   typename T  
>  
class ComPtr;  
  
template<  
   class U  
>  
friend class ComPtr;  

Parameters

T
The interface that the ComPtr represents.

U
A class to which the current ComPtr is a friend. (The template that uses this parameter is protected.)

ComPtr<> declares a type that represents the underlying interface pointer. Use ComPtr<> to declare a variable and then use the arrow member-access operator (->) to access an interface member function.

For more information about smart pointers, see the "COM Smart Pointers" subsection of the COM Coding Practicestopic in the MSDN Library.

Public Typedefs

NameDescription
InterfaceTypeA synonym for the type specified by the T template parameter.

Public Constructors

NameDescription
ComPtr::ComPtr ConstructorIntializes a new instance of the ComPtr class. Overloads provide default, copy, move, and conversion constructors.
ComPtr::~ComPtr DestructorDeinitializes an instance of ComPtr.

Public Methods

NameDescription
ComPtr::As MethodReturns a ComPtr object that represents the interface identified by the specified template parameter.
ComPtr::AsIID MethodReturns a ComPtr object that represents the interface identified by the specified interface ID.
ComPtr::AsWeak MethodRetrieves a weak reference to the current object.
ComPtr::Attach MethodAssociates this ComPtr with the interface type specified by the current template type parameter.
ComPtr::CopyTo MethodCopies the current or specified interface associated with this ComPtr to the specified output pointer.
ComPtr::Detach MethodDisassociates this ComPtr from the interface that it represents.
ComPtr::Get MethodRetrieves a pointer to the interface that is associated with this ComPtr.
ComPtr::GetAddressOf MethodRetrieves the address of the ptr_ data member, which contains a pointer to the interface represented by this ComPtr.
ComPtr::ReleaseAndGetAddressOf MethodReleases the interface associated with this ComPtr and then retrieves the address of the ptr_ data member, which contains a pointer to the interface that was released.
ComPtr::ResetReleases all references for the pointer to the interface that is associated with this ComPtr.
ComPtr::Swap MethodExchanges the interface managed by the current ComPtr with the interface managed by the specified ComPtr.

Protected Methods

NameDescription
ComPtr::InternalAddRef MethodIncrements the reference count of the interface associated with this ComPtr.
ComPtr::InternalRelease MethodPerforms a COM Release operation on the interface associated with this ComPtr.

Public Operators

NameDescription
ComPtr::operator Microsoft::WRL::Details::BoolType OperatorIndicates whether or not a ComPtr is managing the object lifetime of an interface.
ComPtr::operator& OperatorRetrieves the address of the current ComPtr.
ComPtr::operator= OperatorAssigns a value to the current ComPtr.
ComPtr::operator-> OperatorRetrieves a pointer to the type specified by the current template parameter.
ComPtr::operator== OperatorIndicates whether two ComPtr objects are equal.
ComPtr::operator!= OperatorIndicates whether two ComPtr objects are not equal.

Protected Data Members

NameDescription
ComPtr::ptr_ Data MemberContains a pointer to the interface that is associated with, and managed by this ComPtr.

ComPtr

Header: client.h

Namespace: Microsoft::WRL

Microsoft::WRL Namespace

Show: