|
25 | 25 | </Attributes> |
26 | 26 | <Docs> |
27 | 27 | <summary>Class for managing wrappers of COM IUnknown types.</summary> |
28 | | - <remarks>To be added.</remarks> |
| 28 | + <remarks> |
| 29 | + <format type="text/markdown">< 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> |
29 | 83 | </Docs> |
30 | 84 | <Members> |
31 | 85 | <Member MemberName=".ctor"> |
|
0 commit comments