WeakRef::As Method

 

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 WeakRef::As Method.

Sets the specified ComPtr pointer parameter to represent the specified interface.

Syntax

  
template<  
   typename U  
>  
HRESULT As(  
   _Out_ ComPtr<U>* ptr  
);  
  
template<  
   typename U  
>  
HRESULT As(  
   _Out_ Details::ComPtrRef<ComPtr<U>> ptr  
);  

Parameters

U
An interface ID.

ptr
When this operation completes, an object that represents parameter U.

Return Value

  • S_OK if this operation succeeds; otherwise, an HRESULT that indicates the reason the operation failed, and ptr is set to nullptr.

  • S_OK if this operation succeeds, but the current WeakRef object has already been released. Parameter ptr is set to nullptr.

  • S_OK if this operation succeeds, but the current WeakRef object is not derived from parameter U. Parameter ptr is set to nullptr.

Remarks

An error is emitted if parameter U is IWeakReference, or is not derived from IInspectable.

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.

Starting in the Windows 10 SDK, this method does not set the WeakRef instance to nullptr if the weak reference could not be obtained, so you should avoid error-checking code that checks the WeakRef for nullptr. Instead, check ptr for nullptr.

Requirements

Header: client.h

Namespace: Microsoft::WRL

See Also

WeakRef Class