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
Consolidate ComWrappers implementation across platforms (#47982)
* Consolidate ComWrappers implementation across platforms
This should help in implementing dotnet/runtimelab#306
* Fix incorrect and missing partial declarations
* Update src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copy file name to clipboardExpand all lines: src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
+1-114Lines changed: 1 addition & 114 deletions
Original file line number
Diff line number
Diff line change
@@ -10,66 +10,6 @@
10
10
11
11
namespaceSystem.Runtime.InteropServices
12
12
{
13
-
/// <summary>
14
-
/// Enumeration of flags for <see cref="ComWrappers.GetOrCreateComInterfaceForObject(object, CreateComInterfaceFlags)"/>.
15
-
/// </summary>
16
-
[Flags]
17
-
publicenumCreateComInterfaceFlags
18
-
{
19
-
None=0,
20
-
21
-
/// <summary>
22
-
/// The caller will provide an IUnknown Vtable.
23
-
/// </summary>
24
-
/// <remarks>
25
-
/// This is useful in scenarios when the caller has no need to rely on an IUnknown instance
26
-
/// that is used when running managed code is not possible (i.e. during a GC). In traditional
27
-
/// COM scenarios this is common, but scenarios involving <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackertarget">Reference Tracker hosting</see>
28
-
/// calling of the IUnknown API during a GC is possible.
29
-
/// </remarks>
30
-
CallerDefinedIUnknown=1,
31
-
32
-
/// <summary>
33
-
/// Flag used to indicate the COM interface should implement <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackertarget">IReferenceTrackerTarget</see>.
34
-
/// When this flag is passed, the resulting COM interface will have an internal implementation of IUnknown
35
-
/// and as such none should be supplied by the caller.
36
-
/// </summary>
37
-
TrackerSupport=2,
38
-
}
39
-
40
-
/// <summary>
41
-
/// Enumeration of flags for <see cref="ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags)"/>.
42
-
/// </summary>
43
-
[Flags]
44
-
publicenumCreateObjectFlags
45
-
{
46
-
None=0,
47
-
48
-
/// <summary>
49
-
/// Indicate if the supplied external COM object implements the <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetracker">IReferenceTracker</see>.
50
-
/// </summary>
51
-
TrackerObject=1,
52
-
53
-
/// <summary>
54
-
/// Ignore any internal caching and always create a unique instance.
55
-
/// </summary>
56
-
UniqueInstance=2,
57
-
58
-
/// <summary>
59
-
/// Defined when COM aggregation is involved (that is an inner instance supplied).
60
-
/// </summary>
61
-
Aggregation=4,
62
-
63
-
/// <summary>
64
-
/// Check if the supplied instance is actually a wrapper and if so return the underlying
65
-
/// managed object rather than creating a new wrapper.
66
-
/// </summary>
67
-
/// <remarks>
68
-
/// This matches the built-in RCW semantics for COM interop.
69
-
/// </remarks>
70
-
Unwrap=8,
71
-
}
72
-
73
13
/// <summary>
74
14
/// Internal enumeration used by the runtime to indicate the scenario for which ComWrappers is being used.
/// Compute the desired Vtable for <paramref name="obj"/> respecting the values of <paramref name="flags"/>.
191
-
/// </summary>
192
-
/// <param name="obj">Target of the returned Vtables.</param>
193
-
/// <param name="flags">Flags used to compute Vtables.</param>
194
-
/// <param name="count">The number of elements contained in the returned memory.</param>
195
-
/// <returns><see cref="ComInterfaceEntry" /> pointer containing memory for all COM interface entries.</returns>
196
-
/// <remarks>
197
-
/// All memory returned from this function must either be unmanaged memory, pinned managed memory, or have been
198
-
/// allocated with the <see cref="System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(Type, int)"/> API.
199
-
///
200
-
/// If the interface entries cannot be created and a negative <paramref name="count" /> or <code>null</code> and a non-zero <paramref name="count" /> are returned,
201
-
/// the call to <see cref="ComWrappers.GetOrCreateComInterfaceForObject(object, CreateComInterfaceFlags)"/> will throw a <see cref="System.ArgumentException"/>.
@@ -248,17 +152,6 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
248
152
returnobj!;
249
153
}
250
154
251
-
/// <summary>
252
-
/// Create a managed object for the object pointed at by <paramref name="externalComObject"/> respecting the values of <paramref name="flags"/>.
253
-
/// </summary>
254
-
/// <param name="externalComObject">Object to import for usage into the .NET runtime.</param>
255
-
/// <param name="flags">Flags used to describe the external object.</param>
256
-
/// <returns>Returns a managed object associated with the supplied external COM object.</returns>
257
-
/// <remarks>
258
-
/// If the object cannot be created and <code>null</code> is returned, the call to <see cref="ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags)"/> will throw a <see cref="System.ArgumentNullException"/>.
Copy file name to clipboardExpand all lines: src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs
// Licensed to the .NET Foundation under one or more agreements.
2
+
// The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+
usingSystem.Collections;
5
+
usingSystem.Runtime.Versioning;
6
+
7
+
namespaceSystem.Runtime.InteropServices
8
+
{
9
+
/// <summary>
10
+
/// Enumeration of flags for <see cref="ComWrappers.GetOrCreateComInterfaceForObject(object, CreateComInterfaceFlags)"/>.
11
+
/// </summary>
12
+
[Flags]
13
+
publicenumCreateComInterfaceFlags
14
+
{
15
+
None=0,
16
+
17
+
/// <summary>
18
+
/// The caller will provide an IUnknown Vtable.
19
+
/// </summary>
20
+
/// <remarks>
21
+
/// This is useful in scenarios when the caller has no need to rely on an IUnknown instance
22
+
/// that is used when running managed code is not possible (i.e. during a GC). In traditional
23
+
/// COM scenarios this is common, but scenarios involving <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackertarget">Reference Tracker hosting</see>
24
+
/// calling of the IUnknown API during a GC is possible.
25
+
/// </remarks>
26
+
CallerDefinedIUnknown=1,
27
+
28
+
/// <summary>
29
+
/// Flag used to indicate the COM interface should implement <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetrackertarget">IReferenceTrackerTarget</see>.
30
+
/// When this flag is passed, the resulting COM interface will have an internal implementation of IUnknown
31
+
/// and as such none should be supplied by the caller.
32
+
/// </summary>
33
+
TrackerSupport=2,
34
+
}
35
+
36
+
/// <summary>
37
+
/// Enumeration of flags for <see cref="ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags)"/>.
38
+
/// </summary>
39
+
[Flags]
40
+
publicenumCreateObjectFlags
41
+
{
42
+
None=0,
43
+
44
+
/// <summary>
45
+
/// Indicate if the supplied external COM object implements the <see href="https://docs.microsoft.com/windows/win32/api/windows.ui.xaml.hosting.referencetracker/nn-windows-ui-xaml-hosting-referencetracker-ireferencetracker">IReferenceTracker</see>.
46
+
/// </summary>
47
+
TrackerObject=1,
48
+
49
+
/// <summary>
50
+
/// Ignore any internal caching and always create a unique instance.
51
+
/// </summary>
52
+
UniqueInstance=2,
53
+
54
+
/// <summary>
55
+
/// Defined when COM aggregation is involved (that is an inner instance supplied).
56
+
/// </summary>
57
+
Aggregation=4,
58
+
59
+
/// <summary>
60
+
/// Check if the supplied instance is actually a wrapper and if so return the underlying
61
+
/// managed object rather than creating a new wrapper.
62
+
/// </summary>
63
+
/// <remarks>
64
+
/// This matches the built-in RCW semantics for COM interop.
65
+
/// </remarks>
66
+
Unwrap=8,
67
+
}
68
+
69
+
/// <summary>
70
+
/// Class for managing wrappers of COM IUnknown types.
71
+
/// </summary>
72
+
[SupportedOSPlatform("windows")]
73
+
[CLSCompliant(false)]
74
+
publicabstractpartialclassComWrappers
75
+
{
76
+
/// <summary>
77
+
/// Interface type and pointer to targeted VTable.
78
+
/// </summary>
79
+
publicstructComInterfaceEntry
80
+
{
81
+
/// <summary>
82
+
/// Interface IID.
83
+
/// </summary>
84
+
publicGuidIID;
85
+
86
+
/// <summary>
87
+
/// Memory must have the same lifetime as the memory returned from the call to <see cref="ComputeVtables(object, CreateComInterfaceFlags, out int)"/>.
88
+
/// </summary>
89
+
publicIntPtrVtable;
90
+
}
91
+
/// <summary>
92
+
/// ABI for function dispatch of a COM interface.
93
+
/// </summary>
94
+
publicpartialstructComInterfaceDispatch
95
+
{
96
+
publicIntPtrVtable;
97
+
}
98
+
99
+
/// <summary>
100
+
/// Compute the desired Vtable for <paramref name="obj"/> respecting the values of <paramref name="flags"/>.
101
+
/// </summary>
102
+
/// <param name="obj">Target of the returned Vtables.</param>
103
+
/// <param name="flags">Flags used to compute Vtables.</param>
104
+
/// <param name="count">The number of elements contained in the returned memory.</param>
105
+
/// <returns><see cref="ComInterfaceEntry" /> pointer containing memory for all COM interface entries.</returns>
106
+
/// <remarks>
107
+
/// All memory returned from this function must either be unmanaged memory, pinned managed memory, or have been
108
+
/// allocated with the <see cref="System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(Type, int)"/> API.
109
+
///
110
+
/// If the interface entries cannot be created and a negative <paramref name="count" /> or <code>null</code> and a non-zero <paramref name="count" /> are returned,
111
+
/// the call to <see cref="ComWrappers.GetOrCreateComInterfaceForObject(object, CreateComInterfaceFlags)"/> will throw a <see cref="System.ArgumentException"/>.
/// Create a managed object for the object pointed at by <paramref name="externalComObject"/> respecting the values of <paramref name="flags"/>.
117
+
/// </summary>
118
+
/// <param name="externalComObject">Object to import for usage into the .NET runtime.</param>
119
+
/// <param name="flags">Flags used to describe the external object.</param>
120
+
/// <returns>Returns a managed object associated with the supplied external COM object.</returns>
121
+
/// <remarks>
122
+
/// If the object cannot be created and <code>null</code> is returned, the call to <see cref="ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags)"/> will throw a <see cref="System.ArgumentNullException"/>.
0 commit comments