The latest version of this topic can be found at ComPtr::As Method.
Returns a ComPtr object that represents the interface identified by the specified template parameter.
template< typename U > HRESULT As( _Out_ ComPtr<U>* p ) const; template< typename U > HRESULT As( _Out_ Details::ComPtrRef<ComPtr<U>> p ) const;
The interface to be represented by parameter
A ComPtr object that represents the interface specified by parameter
p must not refer to the current ComPtr object.
The first template is the form that you should use in your code. The second template is an internal, helper specialization that supports C++ language features such as the auto type deduction keyword.
S_OK if successful; otherwise, an HRESULT that indicates the error.