|
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">< API is used to provide support for the `IUnknown` ABI independent of the built-in COM interoperability support. `ComWrappers` API exposes the minimal runtime support 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 managed proxy to a native object is called a Runtime Callable Wrapper (RCW), but those terms when used here should not be confused with the built-in features of the same name (i.e. [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 | +1. Efficient mapping between a managed object and a native proxy (e.g. CCW). |
| 39 | +2. Efficient mapping between a native `IUnknown` and its managed proxy (e.g. RCW). |
| 40 | +3. Integration with the Garbage Collector through the [`IReferenceTrackerHost`](https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackerhost) interface contract. |
| 41 | + - Leveraging this is a very advanced scenario. |
| 42 | +
|
| 43 | +### Proxy state |
| 44 | +
|
| 45 | +Provided below are descriptions and illustrations of proxy state after their respective creation. |
| 46 | +
|
| 47 | +In the below illustrations, a strong reference is depicted as a solid line (i.e. `===`) and a weak reference is depicted as a dashed line (i.e. `= = =`). The terms "strong" and "weak" reference should be interpreted as "extending lifetime" and "not extending lifetime" as opposed to implying a specific implementation. |
| 48 | +
|
| 49 | +The state of the managed object and native proxy after a call to [`ComWrappers.GetOrCreateComInterfaceForObject`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.comwrappers.getorcreatecominterfaceforobject) is illustrated below. |
| 50 | +
|
| 51 | +``` |
| 52 | + -------------------- ---------------------- |
| 53 | +| Manage object | | Native proxy | |
| 54 | +| | | Ref count: 1 | |
| 55 | +| ---------------- | | ------------------ | |
| 56 | +| | Weak reference |=| = = = = = = = >| | Strong reference | | |
| 57 | +| | to proxy | |<===============|=| to object | | |
| 58 | +| ---------------- | | ------------------ | |
| 59 | + -------------------- ---------------------- |
| 60 | +``` |
| 61 | +
|
| 62 | +The state of the native object and managed proxy after a call to [`ComWrappers.GetOrCreateObjectForComInstance`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.comwrappers.getorcreateobjectforcominstance) is illustrated below. The concept of "identity" follows the [rules for `IUnknown`](https://docs.microsoft.com/windows/win32/com/rules-for-implementing-queryinterface#objects-must-have-identity). |
| 63 | +
|
| 64 | +``` |
| 65 | + ------------------ ------------------ |
| 66 | +| Native object |< = = = = = =| | |
| 67 | +| Ref count: +1 | | Mapping from | |
| 68 | + ------------------ | native identity | |
| 69 | + ------------------------ | to managed proxy | |
| 70 | +| Managed proxy |< = = =| | |
| 71 | +| Created by ComWrappers | ------------------ |
| 72 | +| implementer. | |
| 73 | +| Optional AddRef() on | |
| 74 | +| native object. | |
| 75 | + ------------------------ |
| 76 | +``` |
| 77 | +Observe in the above illustration 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 (i.e. `ComWrappers` implementer) to ensure the associated lifetime between the native object and its managed proxy. There is an optional strong reference (i.e. `AddRef()`) mentioned in the managed proxy, which is used to support scenario (3) above - see [`CreateObjectFlags.TrackerObject`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.createobjectflags). With this optional strong reference the reference count would be `+2`. |
| 78 | +
|
| 79 | + ]]></format> |
| 80 | + </remarks> |
29 | 81 | </Docs> |
30 | 82 | <Members> |
31 | 83 | <Member MemberName=".ctor"> |
|
0 commit comments