summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2019-01-09 02:27:26 +0100
committerJan Kotas <jkotas@microsoft.com>2019-01-09 09:23:32 -0800
commitc44b38fec5db8c0957cd15dd17164084b4af4011 (patch)
tree56d9151793927e0d51d7ebdf7eb497e1daa52265 /src/System.Private.CoreLib/shared/System
parent3c81b68ca399f16077c159e838da38968494f3a7 (diff)
downloadcoreclr-c44b38fec5db8c0957cd15dd17164084b4af4011.tar.gz
coreclr-c44b38fec5db8c0957cd15dd17164084b4af4011.tar.bz2
coreclr-c44b38fec5db8c0957cd15dd17164084b4af4011.zip
Moves common COM type to shared corelib partition (dotnet/corert#6782)
* Moves common COM type to shared corelib partition * Moves GetHRForException to PInvokeMarshal * Add temporary CORECLR ifdef to ArrayWithOffset * Apply cleanup from CoreCLR Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src/System.Private.CoreLib/shared/System')
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs16
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs98
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs22
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs21
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs13
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs17
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs17
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs19
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs13
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs37
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs25
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs12
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs14
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs23
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs17
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs43
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs29
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs13
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs11
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs20
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs12
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs17
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs20
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs17
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs17
25 files changed, 563 insertions, 0 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
new file mode 100644
index 0000000000..cb640a7a8c
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // To be used on methods that sink reverse P/Invoke calls.
+ // This attribute was a Silverlight security measure, currently ignored.
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public sealed class AllowReversePInvokeCallsAttribute : Attribute
+ {
+ public AllowReversePInvokeCallsAttribute()
+ {
+ }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
new file mode 100644
index 0000000000..d246f55748
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
@@ -0,0 +1,98 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.CompilerServices;
+
+namespace System.Runtime.InteropServices
+{
+ public struct ArrayWithOffset
+ {
+ // From MAX_SIZE_FOR_INTEROP in mlinfo.h
+ private const int MaxSizeForInterop = 0x7ffffff0;
+
+ public ArrayWithOffset(object array, int offset)
+ {
+ m_array = array;
+ m_offset = offset;
+ m_count = 0;
+ m_count = CalculateCount();
+ }
+
+ public object GetArray() => m_array;
+
+ public int GetOffset() => m_offset;
+
+ public override int GetHashCode() => m_count + m_offset;
+
+ public override bool Equals(object obj)
+ {
+ return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj);
+ }
+
+ public bool Equals(ArrayWithOffset obj)
+ {
+ return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
+ }
+
+ public static bool operator ==(ArrayWithOffset a, ArrayWithOffset b)
+ {
+ return a.Equals(b);
+ }
+
+ public static bool operator !=(ArrayWithOffset a, ArrayWithOffset b)
+ {
+ return !(a == b);
+ }
+
+#if !CORECLR // TODO: Cleanup
+ private int CalculateCount()
+ {
+ if (m_array == null)
+ {
+ if (m_offset != 0)
+ {
+ throw new IndexOutOfRangeException(SR.IndexOutOfRange_ArrayWithOffset);
+ }
+
+ return 0;
+ }
+ else
+ {
+ Array arrayObj = m_array as Array;
+ if (arrayObj == null)
+ {
+ throw new ArgumentException(SR.Argument_NotIsomorphic);
+ }
+
+ if (arrayObj.Rank != 1)
+ {
+ throw new ArgumentException(SR.Argument_NotIsomorphic);
+ }
+
+ if (!arrayObj.IsBlittable())
+ {
+ throw new ArgumentException(SR.Argument_NotIsomorphic);
+ }
+
+ int totalSize = checked(arrayObj.Length * arrayObj.GetElementSize());
+ if (totalSize > MaxSizeForInterop)
+ {
+ throw new ArgumentException(SR.Argument_StructArrayTooLarge);
+ }
+
+ if (m_offset > totalSize)
+ {
+ throw new IndexOutOfRangeException(SR.IndexOutOfRange_ArrayWithOffset);
+ }
+
+ return totalSize - m_offset;
+ }
+ }
+#endif // !CORECLR
+
+ private object m_array;
+ private int m_offset;
+ private int m_count;
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
new file mode 100644
index 0000000000..f6eee34264
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // Wrapper that is converted to a variant with VT_BSTR.
+ public sealed class BStrWrapper
+ {
+ public BStrWrapper(string value)
+ {
+ WrappedObject = value;
+ }
+
+ public BStrWrapper(object value)
+ {
+ WrappedObject = (string)value;
+ }
+
+ public string WrappedObject { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
new file mode 100644
index 0000000000..59d79ff443
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherited = false)]
+ public sealed class ClassInterfaceAttribute : Attribute
+ {
+ public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
+ {
+ Value = classInterfaceType;
+ }
+ public ClassInterfaceAttribute(short classInterfaceType)
+ {
+ Value = (ClassInterfaceType)classInterfaceType;
+ }
+
+ public ClassInterfaceType Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
new file mode 100644
index 0000000000..ef1fe84194
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ public enum ClassInterfaceType
+ {
+ None = 0,
+ AutoDispatch = 1,
+ AutoDual = 2
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
new file mode 100644
index 0000000000..4be6622c3d
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
+ public sealed class CoClassAttribute : Attribute
+ {
+ public CoClassAttribute(Type coClass)
+ {
+ CoClass = coClass;
+ }
+
+ public Type CoClass { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
new file mode 100644
index 0000000000..1b84f5f561
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Class, Inherited = false)]
+ public sealed class ComDefaultInterfaceAttribute : Attribute
+ {
+ public ComDefaultInterfaceAttribute(Type defaultInterface)
+ {
+ Value = defaultInterface;
+ }
+
+ public Type Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
new file mode 100644
index 0000000000..d4ccc702e0
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
+ public sealed class ComEventInterfaceAttribute : Attribute
+ {
+ public ComEventInterfaceAttribute(Type SourceInterface, Type EventProvider)
+ {
+ this.SourceInterface = SourceInterface;
+ this.EventProvider = EventProvider;
+ }
+
+ public Type SourceInterface { get; }
+ public Type EventProvider { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
new file mode 100644
index 0000000000..4be75b03b9
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ public enum ComMemberType
+ {
+ Method = 0,
+ PropGet = 1,
+ PropSet = 2
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
new file mode 100644
index 0000000000..484a29a365
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Class, Inherited = true)]
+ public sealed class ComSourceInterfacesAttribute : Attribute
+ {
+ public ComSourceInterfacesAttribute(String sourceInterfaces)
+ {
+ Value = sourceInterfaces;
+ }
+
+ public ComSourceInterfacesAttribute(Type sourceInterface)
+ {
+ Value = sourceInterface.FullName;
+ }
+
+ public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2)
+ {
+ Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName;
+ }
+
+ public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3)
+ {
+ Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName;
+ }
+
+ public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3, Type sourceInterface4)
+ {
+ Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName + "\0" + sourceInterface4.FullName;
+ }
+
+ public String Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
new file mode 100644
index 0000000000..95d8260fcc
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // Wrapper that is converted to a variant with VT_CURRENCY.
+ public sealed class CurrencyWrapper
+ {
+ public CurrencyWrapper(Decimal obj)
+ {
+ WrappedObject = obj;
+ }
+
+ public CurrencyWrapper(Object obj)
+ {
+ if (!(obj is Decimal))
+ throw new ArgumentException(SR.Arg_MustBeDecimal, nameof(obj));
+
+ WrappedObject = (Decimal)obj;
+ }
+
+ public Decimal WrappedObject { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
new file mode 100644
index 0000000000..7b5eddacf4
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
@@ -0,0 +1,12 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ public enum CustomQueryInterfaceMode
+ {
+ Ignore = 0,
+ Allow = 1,
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
new file mode 100644
index 0000000000..1e1d3fd7ea
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // The enum of the return value of IQuerable.GetInterface
+ public enum CustomQueryInterfaceResult
+ {
+ Handled = 0,
+ NotHandled = 1,
+ Failed = 2,
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
new file mode 100644
index 0000000000..8ab7ee2e01
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ //
+ // The DefaultParameterValueAttribute is used in C# to set
+ // the default value for parameters when calling methods
+ // from other languages. This is particularly useful for
+ // methods defined in COM interop interfaces.
+ //
+ [AttributeUsageAttribute(AttributeTargets.Parameter)]
+ public sealed class DefaultParameterValueAttribute : Attribute
+ {
+ public DefaultParameterValueAttribute(object value)
+ {
+ Value = value;
+ }
+
+ public object Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
new file mode 100644
index 0000000000..1f147280c5
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)]
+ public sealed class DispIdAttribute : Attribute
+ {
+ public DispIdAttribute(int dispId)
+ {
+ Value = dispId;
+ }
+
+ public int Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
new file mode 100644
index 0000000000..b5c1d2b0cc
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//
+
+//
+
+/*=============================================================================
+**
+** Class: DispatchWrapper.
+**
+**
+** Purpose: Wrapper that is converted to a variant with VT_DISPATCH.
+**
+**
+=============================================================================*/
+
+namespace System.Runtime.InteropServices
+{
+ public sealed class DispatchWrapper
+ {
+ public DispatchWrapper(Object obj)
+ {
+ if (obj != null)
+ {
+#if CORERT
+ throw new PlatformNotSupportedException();
+#else
+ // Make sure this guy has an IDispatch
+ IntPtr pdisp = Marshal.GetIDispatchForObject(obj);
+
+ // If we got here without throwing an exception, the QI for IDispatch succeeded.
+ Marshal.Release(pdisp);
+
+ WrappedObject = obj;
+#endif
+ }
+ }
+
+ public object WrappedObject { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
new file mode 100644
index 0000000000..d25f0231a4
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // Wrapper that is converted to a variant with VT_ERROR.
+ public sealed class ErrorWrapper
+ {
+ public ErrorWrapper(int errorCode)
+ {
+ ErrorCode = errorCode;
+ }
+
+ public ErrorWrapper(object errorCode)
+ {
+ if (!(errorCode is int))
+ throw new ArgumentException(SR.Arg_MustBeInt32, nameof(errorCode));
+ ErrorCode = (int)errorCode;
+ }
+
+ public ErrorWrapper(Exception e)
+ {
+ ErrorCode = Marshal.GetHRForException(e);
+ }
+
+ public int ErrorCode { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
new file mode 100644
index 0000000000..6dd90e2dac
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // This the base interface that custom adapters can chose to implement when they want to expose the underlying object.
+ public interface ICustomAdapter
+ {
+ [return: MarshalAs(UnmanagedType.IUnknown)]
+ object GetUnderlyingObject();
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
new file mode 100644
index 0000000000..799db6a2d3
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
@@ -0,0 +1,11 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ public interface ICustomFactory
+ {
+ MarshalByRefObject CreateInstance(Type serverType);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
new file mode 100644
index 0000000000..cf442d4fde
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // This the base interface that must be implemented by all custom marshalers.
+ public interface ICustomMarshaler
+ {
+ object MarshalNativeToManaged(IntPtr pNativeData);
+
+ IntPtr MarshalManagedToNative(object ManagedObj);
+
+ void CleanUpNativeData(IntPtr pNativeData);
+
+ void CleanUpManagedData(object ManagedObj);
+
+ int GetNativeDataSize();
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
new file mode 100644
index 0000000000..a91fd7f5fb
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
@@ -0,0 +1,12 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // This the interface that be implemented by class that want to customize the behavior of QueryInterface.
+ public interface ICustomQueryInterface
+ {
+ CustomQueryInterfaceResult GetInterface([In]ref Guid iid, out IntPtr ppv);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
new file mode 100644
index 0000000000..50d69ee6e3
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Class, Inherited = false)]
+ public sealed class ProgIdAttribute : Attribute
+ {
+ public ProgIdAttribute(String progId)
+ {
+ Value = progId;
+ }
+
+ public String Value { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
new file mode 100644
index 0000000000..6dfe9df780
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
+ public sealed class TypeIdentifierAttribute : Attribute
+ {
+ public TypeIdentifierAttribute() { }
+ public TypeIdentifierAttribute(string scope, string identifier)
+ {
+ Scope = scope;
+ Identifier = identifier;
+ }
+
+ public string Scope { get; }
+ public string Identifier { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
new file mode 100644
index 0000000000..9d1599af6e
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // Wrapper that is converted to a variant with VT_UNKNOWN.
+ public sealed class UnknownWrapper
+ {
+ public UnknownWrapper(Object obj)
+ {
+ WrappedObject = obj;
+ }
+
+ public Object WrappedObject { get; }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
new file mode 100644
index 0000000000..3d75da1994
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+ // Wrapper that is converted to a variant with VT_BYREF | VT_VARIANT.
+ public sealed class VariantWrapper
+ {
+ public VariantWrapper(Object obj)
+ {
+ WrappedObject = obj;
+ }
+
+ public Object WrappedObject { get; }
+ }
+}