Skip to content

Commit 4a94a07

Browse files
Merge pull request dotnet#5042 from dotnet/AaronRobinsonMSFT-patch-1
Update ComWrappers.xml
2 parents 7e80efd + 33ca074 commit 4a94a07

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

xml/System.Runtime.InteropServices/ComWrappers.xml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,61 @@
2525
</Attributes>
2626
<Docs>
2727
<summary>Class for managing wrappers of COM IUnknown types.</summary>
28-
<remarks>To be added.</remarks>
28+
<remarks>
29+
<format type="text/markdown"><![CDATA[
30+
31+
## Remarks
32+
33+
The <xref:System.Runtime.InteropServices.ComWrappers> API provides support for the `IUnknown` ABI, independent of the built-in COM interoperability support. The `ComWrappers` API exposes the minimal runtime support that's needed for developers to replace the built-in version in an efficient manner.
34+
35+
Traditionally in the runtime, a native proxy to managed object is called a COM Callable Wrapper (CCW), and a managed proxy to a native object is called a Runtime Callable Wrapper (RCW). However, when used here, those terms should not be confused with the built-in features of the same name (that is, [CCW](https://docs.microsoft.com/dotnet/standard/native-interop/com-callable-wrapper) and [RCW](https://docs.microsoft.com/dotnet/standard/native-interop/runtime-callable-wrapper)). Unlike the built-in features, a majority of the responsibility for accurate lifetime management, dispatching methods, and marshalling of arguments and return values is left to the `ComWrappers` implementer.
36+
37+
"Minimal support" is defined by the following features:
38+
39+
1. Efficient mapping between a managed object and a native proxy (for example, CCW).
40+
2. Efficient mapping between a native `IUnknown` and its managed proxy (for example, RCW).
41+
3. Integration with the garbage collector through the [IReferenceTrackerHost](/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackerhost) interface contract.
42+
43+
Leveraging this is an advanced scenario.
44+
45+
### Proxy state
46+
47+
This section provides descriptions and illustrations of native and managed proxy state after their respective creation.
48+
49+
In the following illustrations, a strong reference is depicted as a solid line (`===`) and a weak reference is depicted as a dashed line (`= = =`). The terms "strong reference" and "weak reference" should be interpreted as "extending lifetime" and "not extending lifetime", as opposed to implying a specific implementation.
50+
51+
The following illustration shows the state of the managed object and native proxy after a call to <xref:System.Runtime.InteropServices.ComWrappers.GetOrCreateComInterfaceForObject(System.Object,System.Runtime.InteropServices.CreateComInterfaceFlags)?displayProperty=nameWithType>.
52+
53+
```
54+
-------------------- ----------------------
55+
| Managed object | | Native proxy |
56+
| | | Ref count: 1 |
57+
| ---------------- | | ------------------ |
58+
| | Weak reference |=| = = = = = = = >| | Strong reference | |
59+
| | to proxy | |<===============|=| to object | |
60+
| ---------------- | | ------------------ |
61+
-------------------- ----------------------
62+
```
63+
64+
The next illustration shows the state of the native object and managed proxy after a call to <xref:System.Runtime.InteropServices.ComWrappers.GetOrCreateObjectForComInstance(System.IntPtr,System.Runtime.InteropServices.CreateObjectFlags)?displayProperty=nameWithType>. The concept of "identity" follows the [rules for `IUnknown`](https://docs.microsoft.com/windows/win32/com/rules-for-implementing-queryinterface#objects-must-have-identity).
65+
66+
```
67+
------------------ ------------------
68+
| Native object |< = = = = = =| |
69+
| Ref count: +1 | | Mapping from |
70+
------------------ | native identity |
71+
------------------------ | to managed proxy |
72+
| Managed proxy |< = = =| |
73+
| Created by ComWrappers | ------------------
74+
| implementer. |
75+
| Optional AddRef() on |
76+
| native object. |
77+
------------------------
78+
```
79+
Observe that only weak references exist from the runtime perspective. The `+1` reference count on the native object is assumed to be performed by the managed proxy creator (that is, the `ComWrappers` implementer) to ensure the associated lifetime between the native object and its managed proxy. There is an optional strong reference (that is, `AddRef()`) mentioned in the managed proxy, which is used to support scenario (3) mentioned earlier. See <xref:System.Runtime.InteropServices.CreateObjectFlags.TrackerObject?displayProperty=nameWithType>. With this optional strong reference, the reference count would be `+2`.
80+
81+
]]></format>
82+
</remarks>
2983
</Docs>
3084
<Members>
3185
<Member MemberName=".ctor">

0 commit comments

Comments
 (0)