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.

WeakRef Class

Represents a weak reference that can be used by only the Windows Runtime, not classic COM. A weak reference represents an object that might or might not be accessible.

class WeakRef : public ComPtr<IWeakReference>

A WeakRef object maintains a strong reference, which is associated with an object, and can be valid or invalid. Call the As() or AsIID() method to obtain a strong reference. When the strong reference is valid, it can access the associated object. When the strong reference is invalid (nullptr), the associated object is inaccessible.

A WeakRef object is typically used to represent an object whose existence is controlled by an external thread or application. For example, construct a WeakRef object from a reference to a file object. While the file is open, the strong reference is valid. But if the file is closed, the strong reference becomes invalid.

Name

Description

WeakRef::WeakRef Constructor

Initializes a new instance of the WeakRef class.

WeakRef::~WeakRef Destructor

Deinitializes the current instance of the WeakRef class.

Name

Description

WeakRef::As Method

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

WeakRef::AsIID Method

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

WeakRef::CopyTo Method

Assigns a pointer to an interface, if available, to the specified pointer variable.

Name

Description

WeakRef::operator& Operator

Returns a ComPtrRef object that represents the current WeakRef object.

Header: client.h

Namespace: Microsoft::WRL

Show:
© 2014 Microsoft