Skip to content

Commit 7adfb65

Browse files
Consolidated the WeakReference class.
1 parent 794a117 commit 7adfb65

7 files changed

+126
-285
lines changed

docs/windows/weakreference-class1.md

Lines changed: 126 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "WeakReference Class1 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "09/24/2018"
55
ms.technology: ["cpp-windows"]
66
ms.topic: "reference"
7-
f1_keywords: ["implements/Microsoft::WRL::Details::WeakReference"]
7+
f1_keywords: ["implements/Microsoft::WRL::Details::WeakReference", "implements/Microsoft::WRL::Details::WeakReference::DecrementStrongReference", "implements/Microsoft::WRL::Details::WeakReference::IncrementStrongReference", "implements/Microsoft::WRL::Details::WeakReference::Resolve", "implements/Microsoft::WRL::Details::WeakReference::SetUnknown", "implements/Microsoft::WRL::Details::WeakReference::~WeakReference", "implements/Microsoft::WRL::Details::WeakReference::WeakReference"]
88
dev_langs: ["C++"]
9-
helpviewer_keywords: ["WeakReference class"]
9+
helpviewer_keywords: ["Microsoft::WRL::Details::WeakReference class", "Microsoft::WRL::Details::WeakReference::DecrementStrongReference method", "Microsoft::WRL::Details::WeakReference::IncrementStrongReference method", "Microsoft::WRL::Details::WeakReference::Resolve method", "Microsoft::WRL::Details::WeakReference::SetUnknown method", "Microsoft::WRL::Details::WeakReference::~WeakReference, destructor", "Microsoft::WRL::Details::WeakReference::WeakReference, constructor"]
1010
ms.assetid: 3f4c956b-dbbd-49b1-8cfa-9509a9956c97
1111
author: "mikeblome"
1212
ms.author: "mblome"
@@ -26,29 +26,29 @@ class WeakReference;
2626

2727
Represents a *weak reference* that can be used with the Windows Runtime or classic COM. A weak reference represents an object that might or might not be accessible.
2828

29-
A **WeakReference** object maintains a *strong reference*, which is a pointer to an object, and a *strong reference count*, which is the number of copies of the strong reference that have been distributed by the `Resolve()` method. While the strong reference count is nonzero, the strong reference is valid and the object is accessible. When the strong reference count becomes zero, the strong reference is invalid and the object is inaccessible.
29+
A `WeakReference` object maintains a *strong reference*, which is a pointer to an object, and a *strong reference count*, which is the number of copies of the strong reference that have been distributed by the `Resolve()` method. While the strong reference count is nonzero, the strong reference is valid and the object is accessible. When the strong reference count becomes zero, the strong reference is invalid and the object is inaccessible.
3030

31-
A **WeakReference** object is typically used to represent an object whose existence is controlled by an external thread or application. For example, construct a **WeakReference** 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.
31+
A `WeakReference` object is typically used to represent an object whose existence is controlled by an external thread or application. For example, construct a `WeakReference` 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.
3232

33-
The **WeakReference** methods are thread safe.
33+
The `WeakReference` methods are thread safe.
3434

3535
## Members
3636

3737
### Public Constructors
3838

39-
|Name|Description|
40-
|----------|-----------------|
41-
|[WeakReference::WeakReference Constructor](../windows/weakreference-weakreference-constructor.md)|Initializes a new instance of the **WeakReference** class.|
42-
|[WeakReference::~WeakReference Destructor](../windows/weakreference-tilde-weakreference-destructor.md)|Deinitializes (destroys) the current instance of the **WeakReference** class.|
39+
Name | Description
40+
----------------------------------------------------- | ---------------------------------------------------------------------------
41+
[WeakReference::WeakReference](#weakreference) | Initializes a new instance of the `WeakReference` class.
42+
[WeakReference::~WeakReference](#tilde-weakreference) | Deinitializes (destroys) the current instance of the `WeakReference` class.
4343

4444
### Public Methods
4545

46-
|Name|Description|
47-
|----------|-----------------|
48-
|[WeakReference::DecrementStrongReference Method](../windows/weakreference-decrementstrongreference-method.md)|Decrements the strong reference count of the current **WeakReference** object.|
49-
|[WeakReference::IncrementStrongReference Method](../windows/weakreference-incrementstrongreference-method.md)|Increments the strong reference count of the current **WeakReference** object.|
50-
|[WeakReference::Resolve Method](../windows/weakreference-resolve-method.md)|Sets the specified pointer to the current strong reference value if the strong reference count is nonzero.|
51-
|[WeakReference::SetUnknown Method](../windows/weakreference-setunknown-method.md)|Sets the strong reference of the current **WeakReference** object to the specified interface pointer.|
46+
Name | Description
47+
-------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------
48+
[WeakReference::DecrementStrongReference](#decrementstrongreference) | Decrements the strong reference count of the current `WeakReference` object.
49+
[WeakReference::IncrementStrongReference](#incrementstrongreference) | Increments the strong reference count of the current `WeakReference` object.
50+
[WeakReference::Resolve](#resolve) | Sets the specified pointer to the current strong reference value if the strong reference count is nonzero.
51+
[WeakReference::SetUnknown](#setunknown) | Sets the strong reference of the current `WeakReference` object to the specified interface pointer.
5252

5353
## Inheritance Hierarchy
5454

@@ -60,6 +60,114 @@ The **WeakReference** methods are thread safe.
6060

6161
**Namespace:** Microsoft::WRL::Details
6262

63-
## See Also
63+
## <a name="tilde-weakreference"></a>WeakReference::~WeakReference
6464

65-
[Microsoft::WRL::Details Namespace](../windows/microsoft-wrl-details-namespace.md)
65+
Supports the WRL infrastructure and is not intended to be used directly from your code.
66+
67+
```cpp
68+
virtual ~WeakReference();
69+
```
70+
71+
### Return Value
72+
73+
### Remarks
74+
75+
Deinitializes the current instance of the `WeakReference` class.
76+
77+
## <a name="decrementstrongreference"></a>WeakReference::DecrementStrongReference
78+
79+
Supports the WRL infrastructure and is not intended to be used directly from your code.
80+
81+
```cpp
82+
ULONG DecrementStrongReference();
83+
```
84+
85+
### Remarks
86+
87+
Decrements the strong reference count of the current `WeakReference` object.
88+
89+
When the strong reference count becomes zero, the strong reference is set to `nullptr`.
90+
91+
### Return Value
92+
93+
The decremented strong reference count.
94+
95+
## <a name="incrementstrongreference"></a>WeakReference::IncrementStrongReference
96+
97+
Supports the WRL infrastructure and is not intended to be used directly from your code.
98+
99+
```cpp
100+
ULONG IncrementStrongReference();
101+
```
102+
103+
### Return Value
104+
105+
The incremented strong reference count.
106+
107+
### Remarks
108+
109+
Increments the strong reference count of the current `WeakReference` object.
110+
111+
## <a name="resolve"></a>WeakReference::Resolve
112+
113+
Supports the WRL infrastructure and is not intended to be used directly from your code.
114+
115+
```cpp
116+
STDMETHOD(Resolve)
117+
(REFIID riid,
118+
_Deref_out_opt_ IInspectable **ppvObject
119+
);
120+
```
121+
122+
### Parameters
123+
124+
*riid*<br/>
125+
An interface ID.
126+
127+
*ppvObject*<br/>
128+
When this operation completes, a copy of the current strong reference if the strong reference count is nonzero.
129+
130+
### Return Value
131+
132+
- S_OK if this operation is successful and the strong reference count is zero. The *ppvObject* parameter is set to `nullptr`.
133+
134+
- S_OK if this operation is successful and the strong reference count is nonzero. The *ppvObject* parameter is set to the strong reference.
135+
136+
- Otherwise, an HRESULT that indicates the reason this operation failed.
137+
138+
### Remarks
139+
140+
Sets the specified pointer to the current strong reference value if the strong reference count is nonzero.
141+
142+
## <a name="setunknown"></a>WeakReference::SetUnknown
143+
144+
Supports the WRL infrastructure and is not intended to be used directly from your code.
145+
146+
```cpp
147+
void SetUnknown(
148+
_In_ IUnknown* unk
149+
);
150+
```
151+
152+
### Parameters
153+
154+
*unk*<br/>
155+
A pointer to the `IUnknown` interface of an object.
156+
157+
### Remarks
158+
159+
Sets the strong reference of the current `WeakReference` object to the specified interface pointer.
160+
161+
## <a name="weakreference"></a>WeakReference::WeakReference
162+
163+
Supports the WRL infrastructure and is not intended to be used directly from your code.
164+
165+
```cpp
166+
WeakReference();
167+
```
168+
169+
### Remarks
170+
171+
Initializes a new instance of the `WeakReference` class.
172+
173+
The strong reference pointer for the `WeakReference` object is initialized to `nullptr`, and the strong reference count is initialized to 1.

docs/windows/weakreference-decrementstrongreference-method.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/windows/weakreference-incrementstrongreference-method.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

docs/windows/weakreference-resolve-method.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

docs/windows/weakreference-setunknown-method.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)