You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
13
12
@@ -19,26 +18,26 @@ class WeakRef : public ComPtr<IWeakReference>;
19
18
20
19
## Members
21
20
22
-
### Public Constructors
21
+
### Public constructors
23
22
24
23
|Name|Description|
25
24
|----------|-----------------|
26
-
|[WeakRef::WeakRef Constructor](#weakref)|Initializes a new instance of the `WeakRef` class.|
27
-
|[WeakRef::~WeakRef Destructor](#tilde-weakref)|Deinitializes the current instance of the `WeakRef` class.|
25
+
|[`WeakRef::WeakRef` constructor](#weakref)|Initializes a new instance of the `WeakRef` class.|
26
+
|[`WeakRef::~WeakRef` destructor](#tilde-weakref)|Deinitializes the current instance of the `WeakRef` class.|
28
27
29
-
### Public Methods
28
+
### Public methods
30
29
31
30
|Name|Description|
32
31
|----------|-----------------|
33
-
|[WeakRef::As Method](#as)|Sets the specified `ComPtr` pointer parameter to represent the specified interface.|
34
-
|[WeakRef::AsIID Method](#asiid)|Sets the specified `ComPtr` pointer parameter to represent the specified interface ID.|
35
-
|[WeakRef::CopyTo Method](#copyto)|Assigns a pointer to an interface, if available, to the specified pointer variable.|
32
+
|[`WeakRef::As`](#as)|Sets the specified `ComPtr` pointer parameter to represent the specified interface.|
33
+
|[`WeakRef::AsIID`](#asiid)|Sets the specified `ComPtr` pointer parameter to represent the specified interface ID.|
34
+
|[`WeakRef::CopyTo`](#copyto)|Assigns a pointer to an interface, if available, to the specified pointer variable.|
36
35
37
-
### Public Operators
36
+
### Public operators
38
37
39
38
|Name|Description|
40
39
|----------|-----------------|
41
-
|[WeakRef::operator& Operator](#operator-ampersand-operator)|Returns a `ComPtrRef` object that represents the current `WeakRef` object.|
40
+
|[`WeakRef::operator&`](#operator-ampersand-operator)|Returns a `ComPtrRef` object that represents the current `WeakRef` object.|
42
41
43
42
## Remarks
44
43
@@ -65,7 +64,7 @@ if(wr == nullptr)
65
64
}
66
65
```
67
66
68
-
The above code does not work when using the Windows 10 SDK (or later). Instead, check the pointer that was passed in for **`nullptr`**.
67
+
The above code doesn't work when using the Windows 10 SDK (or later). Instead, check the pointer that was passed in for **`nullptr`**.
Initializes a new instance of the `WeakRef` class.
90
+
91
+
```cpp
92
+
WeakRef();
93
+
WeakRef(
94
+
decltype(__nullptr)
95
+
);
96
+
97
+
WeakRef(
98
+
_In_opt_ IWeakReference* ptr
99
+
);
100
+
101
+
WeakRef(
102
+
const ComPtr<IWeakReference>& ptr
103
+
);
104
+
105
+
WeakRef(
106
+
const WeakRef& ptr
107
+
);
108
+
109
+
WeakRef(
110
+
_Inout_ WeakRef&& ptr
111
+
);
112
+
```
113
+
114
+
### Parameters
115
+
116
+
*`ptr`*\
117
+
A pointer, reference, or rvalue-reference to an existing object that initializes the current `WeakRef` object.
118
+
119
+
### Remarks
86
120
87
-
**Namespace:** Microsoft::WRL
121
+
The first constructor initializes an empty `WeakRef` object. The second constructor initializes a `WeakRef` object from a pointer to the `IWeakReference` interface. The third constructor initializes a `WeakRef` object from a reference to a `ComPtr<IWeakReference>` object. The fourth and fifth constructors initialize a `WeakRef` object from another `WeakRef` object.
Deinitializes the current instance of the `WeakRef` class.
92
126
93
127
```cpp
94
128
~WeakRef();
95
129
```
96
130
97
-
## <aname="as"></a> WeakRef::As Method
131
+
## <aname="as"></a> `WeakRef::As`
98
132
99
133
Sets the specified `ComPtr` pointer parameter to represent the specified interface.
100
134
@@ -112,29 +146,29 @@ HRESULT As(
112
146
113
147
### Parameters
114
148
115
-
*U*<br/>
149
+
*`U`*\
116
150
An interface ID.
117
151
118
-
*ptr*<br/>
152
+
*`ptr`*\
119
153
When this operation completes, an object that represents parameter *U*.
120
154
121
-
### Return Value
155
+
### Return value
122
156
123
-
- S_OK if this operation succeeds; otherwise, an HRESULT that indicates the reason the operation failed, and *ptr* is set to **`nullptr`**.
157
+
-`S_OK` if this operation succeeds; otherwise, an HRESULT that indicates the reason the operation failed, and *`ptr`* is set to **`nullptr`**.
124
158
125
-
- S_OK if this operation succeeds, but the current `WeakRef` object has already been released. Parameter *ptr* is set to **`nullptr`**.
159
+
-`S_OK` if this operation succeeds, but the current `WeakRef` object has already been released. Parameter *`ptr`* is set to **`nullptr`**.
126
160
127
-
- S_OK if this operation succeeds, but the current `WeakRef` object is not derived from parameter *U*. Parameter *ptr* is set to **`nullptr`**.
161
+
-`S_OK` if this operation succeeds, but the current `WeakRef` object isn't derived from parameter *`U`*. Parameter *`ptr`* is set to **`nullptr`**.
128
162
129
163
### Remarks
130
164
131
-
An error is emitted if parameter *U* is `IWeakReference`, or is not derived from `IInspectable`.
165
+
An error is emitted if parameter *`U`* is `IWeakReference`, or isn't derived from `IInspectable`.
132
166
133
-
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](../../cpp/auto-cpp.md) type deduction keyword.
167
+
The first template is the form that you should use in your code. The second template is an internal, helper specialization; it supports C++ language features such as the [`auto`](../../cpp/auto-cpp.md) type deduction keyword.
134
168
135
-
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`**.
169
+
Starting in the Windows 10 SDK, this method doesn't set the `WeakRef` instance to **`nullptr`** if the weak reference couldn't be obtained, so you should avoid error-checking code that checks the `WeakRef` for **`nullptr`**. Instead, check *ptr* for **`nullptr`**.
136
170
137
-
## <aname="asiid"></a> WeakRef::AsIID Method
171
+
## <aname="asiid"></a> `WeakRef::AsIID`
138
172
139
173
Sets the specified `ComPtr` pointer parameter to represent the specified interface ID.
140
174
@@ -147,29 +181,29 @@ HRESULT AsIID(
147
181
148
182
### Parameters
149
183
150
-
*riid*<br/>
184
+
*`riid`*\
151
185
An interface ID.
152
186
153
-
*ptr*<br/>
154
-
When this operation completes, an object that represents parameter *riid*.
187
+
*`ptr`*\
188
+
When this operation completes, an object that represents parameter *`riid`*.
155
189
156
-
### Return Value
190
+
### Return value
157
191
158
-
- S_OK if this operation succeeds; otherwise, an HRESULT that indicates the reason the operation failed, and *ptr* is set to **`nullptr`**.
192
+
-`S_OK` if this operation succeeds; otherwise, an HRESULT that indicates the reason the operation failed, and *`ptr`* is set to **`nullptr`**.
159
193
160
-
- S_OK if this operation succeeds, but the current `WeakRef` object has already been released. Parameter *ptr* is set to **`nullptr`**.
194
+
-`S_OK` if this operation succeeds, but the current `WeakRef` object has already been released. Parameter *`ptr`* is set to **`nullptr`**.
161
195
162
-
- S_OK if this operation succeeds, but the current `WeakRef` object is not derived from parameter *riid*. Parameter *ptr* is set to **`nullptr`**. (For more information, see Remarks.)
196
+
-`S_OK` if this operation succeeds, but the current `WeakRef` object isn't derived from parameter *`riid`*. Parameter *`ptr`* is set to **`nullptr`**. (For more information, see Remarks.)
163
197
164
198
### Remarks
165
199
166
-
An error is emitted if parameter *riid* is not derived from `IInspectable`. This error supersedes the return value.
200
+
An error is emitted if parameter *`riid`* isn't derived from `IInspectable`. This error supersedes the return value.
167
201
168
-
The first template is the form that you should use in your code. The second template (not shown here, but declared in the header file) is an internal, helper specialization that supports C++ language features such as the [auto](../../cpp/auto-cpp.md) type deduction keyword.
202
+
The first template is the form that you should use in your code. The second template (not shown here, but declared in the header file) is an internal, helper specialization that supports C++ language features such as the [`auto`](../../cpp/auto-cpp.md) type deduction keyword.
169
203
170
-
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`**.
204
+
Starting in the Windows 10 SDK, this method doesn't set the `WeakRef` instance to **`nullptr`** if the weak reference couldn't be obtained, so you should avoid error-checking code that checks the `WeakRef` for **`nullptr`**. Instead, check *`ptr`* for **`nullptr`**.
171
205
172
-
## <aname="copyto"></a> WeakRef::CopyTo Method
206
+
## <aname="copyto"></a> `WeakRef::CopyTo`
173
207
174
208
Assigns a pointer to an interface, if available, to the specified pointer variable.
175
209
@@ -191,73 +225,37 @@ HRESULT CopyTo(
191
225
192
226
### Parameters
193
227
194
-
*U*<br/>
195
-
Pointer an `IInspectable` interface. An error is emitted if *U* is not derived from `IInspectable`.
228
+
*`U`*\
229
+
Pointer an `IInspectable` interface. An error is emitted if *`U`* isn't derived from `IInspectable`.
196
230
197
-
*riid*<br/>
198
-
An interface ID. An error is emitted if *riid* is not derived from `IWeakReference`.
231
+
*`riid`*\
232
+
An interface ID. An error is emitted if *`riid`* isn't derived from `IWeakReference`.
199
233
200
-
*ptr*<br/>
201
-
A doubly-indirect pointer to `IInspectable` or `IWeakReference`.
234
+
*`ptr`*\
235
+
A doublyindirect pointer to `IInspectable` or `IWeakReference`.
202
236
203
-
### Return Value
237
+
### Return value
204
238
205
-
S_OK if successful; otherwise, an HRESULT that describes the failure. For more information, see **Remarks**.
239
+
`S_OK` if successful; otherwise, an HRESULT that describes the failure. For more information, see **Remarks**.
206
240
207
241
### Remarks
208
242
209
-
A return value of S_OK means that this operation succeeded, but doesn't indicate whether the weak reference was resolved to a strong reference. If S_OK is returned, test that parameter *p* is a strong reference; that is, parameter *p* isn't equal to **`nullptr`**.
243
+
A return value of `S_OK` means that this operation succeeded, but doesn't indicate whether the weak reference was resolved to a strong reference. If `S_OK` is returned, test that parameter *`ptr`* is a strong reference; that is, parameter *`ptr`* isn't equal to **`nullptr`**.
210
244
211
-
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`**.
245
+
Starting in the Windows 10 SDK, this method doesn't set the `WeakRef` instance to **`nullptr`** if the weak reference couldn't be obtained, so you should avoid error checking code that checks the `WeakRef` for **`nullptr`**. Instead, check *`ptr`* for **`nullptr`**.
Initializes a new instance of the `WeakRef` class.
232
-
233
-
```cpp
234
-
WeakRef();
235
-
WeakRef(
236
-
decltype(__nullptr)
237
-
);
238
-
239
-
WeakRef(
240
-
_In_opt_ IWeakReference* ptr
241
-
);
242
-
243
-
WeakRef(
244
-
const ComPtr<IWeakReference>& ptr
245
-
);
246
-
247
-
WeakRef(
248
-
const WeakRef& ptr
249
-
);
250
-
251
-
WeakRef(
252
-
_Inout_ WeakRef&& ptr
253
-
);
254
-
```
255
-
256
-
### Parameters
257
-
258
-
*ptr*<br/>
259
-
A pointer, reference, or rvalue-reference to an existing object that initializes the current `WeakRef` object.
260
-
261
-
### Remarks
262
-
263
-
The first constructor initializes an empty `WeakRef` object. The second constructor initializes a `WeakRef` object from a pointer to the `IWeakReference` interface. The third constructor initializes a `WeakRef` object from a reference to a `ComPtr<IWeakReference>` object. The fourth and fifth constructors initializes a `WeakRef` object from another `WeakRef` object.
261
+
`WeakRef::operator&` is an internal helper operator that's not meant to be used in your code.
0 commit comments