diff --git a/src/Benchmarks/ReflectionPerf.cs b/src/Benchmarks/ReflectionPerf.cs index 984234cb5..a7817bb2e 100644 --- a/src/Benchmarks/ReflectionPerf.cs +++ b/src/Benchmarks/ReflectionPerf.cs @@ -64,6 +64,14 @@ public object ExecuteMarshalingForString() public object ExecuteMarshalingForCustomObject() { return instance.NewWrappedClassObject; + } + + [Benchmark] + public int ExecuteMarshalingForDelegate() + { + int y = 1; + instance.CallForInt(() => y); + return y; } [Benchmark] @@ -120,6 +128,90 @@ public object ExistingDictionaryLookup3() { var dict = instance.ExistingDictionary; return dict["a"]; + } + + [Benchmark] + public int GetNullableInt() + { + return instance.NullableInt.Value; + } + + [Benchmark] + public void SetNullableInt() + { + instance.NullableInt = new Nullable(4); + } + + [Benchmark] + public object GetNullableBittableStruct() + { + return instance.NullableBlittableStruct.Value; + } + + [Benchmark] + public void SetNullableBittableStruct() + { + BlittableStruct blittableStruct = new BlittableStruct() { i32 = 2 }; + instance.NullableBlittableStruct = new Nullable(blittableStruct); + } + + [Benchmark] + public object GetNullableTimeSpan() + { + return instance.NullableTimeSpan.Value; + } + + [Benchmark] + public void SetNullableTimeSpan() + { + TimeSpan timeSpan = new TimeSpan(100); + instance.NullableTimeSpan = new Nullable(timeSpan); + } + + [Benchmark] + public object GetNullableNonBittableStruct() + { + return instance.NullableNonBlittableStruct.Value; + } + + [Benchmark] + public void SetNullableNonBittableStruct() + { + NonBlittable nonBlittable = new NonBlittable() { A = true, C = "beta" }; + instance.NullableNonBlittableStruct = new Nullable(nonBlittable); + } + + [Benchmark] + public void SetNullableDelegate() + { + int z; + System.EventHandler s = (object sender, int value) => z = value; + instance.NewTypeErasedNullableObject = s; + } + + [Benchmark] + public void SetNullableIntDelegate() + { + ProvideInt s = () => 4; + instance.BoxedDelegate = s; + } + + [Benchmark] + public object GetNullableIntDelegate() + { + return instance.BoxedDelegate as ProvideInt; + } + + [Benchmark] + public object GetNewIntDelegate() + { + return instance.NewIntDelegate; + } + + [Benchmark] + public object GetExistingIntDelegate() + { + return instance.ExistingIntDelegate; } [Benchmark] diff --git a/src/Tests/TestComponentCSharp/Class.cpp b/src/Tests/TestComponentCSharp/Class.cpp index 023771576..95b2b55e5 100644 --- a/src/Tests/TestComponentCSharp/Class.cpp +++ b/src/Tests/TestComponentCSharp/Class.cpp @@ -1407,6 +1407,11 @@ namespace winrt::TestComponentCSharp::implementation return winrt::unbox_value(obj); } + winrt::TestComponentCSharp::ProvideInt Class::UnboxDelegate(WF::IInspectable const& obj) + { + return winrt::unbox_value(obj); + } + com_array Class::UnboxInt32Array(WF::IInspectable const& obj) { return obj.as>().Value(); @@ -1462,6 +1467,12 @@ namespace winrt::TestComponentCSharp::implementation return winrt::box_value(hstring{}); } + WF::IInspectable Class::BoxedDelegate() + { + TestComponentCSharp::ProvideUri handler = [] { return Windows::Foundation::Uri(L"http://microsoft.com"); }; + return winrt::box_value(handler); + } + hstring Class::Catch(hstring const& /*params*/, hstring& /*lock*/) { // Compile-only test for keyword escaping diff --git a/src/Tests/TestComponentCSharp/Class.h b/src/Tests/TestComponentCSharp/Class.h index 694d3d900..e6689c15b 100644 --- a/src/Tests/TestComponentCSharp/Class.h +++ b/src/Tests/TestComponentCSharp/Class.h @@ -355,6 +355,7 @@ namespace winrt::TestComponentCSharp::implementation static int32_t UnboxInt32(IInspectable const& obj); static bool UnboxBoolean(IInspectable const& obj); static hstring UnboxString(IInspectable const& obj); + static TestComponentCSharp::ProvideInt UnboxDelegate(IInspectable const& obj); static com_array UnboxInt32Array(IInspectable const& obj); static com_array UnboxBooleanArray(IInspectable const& obj); static com_array UnboxStringArray(IInspectable const& obj); @@ -368,6 +369,7 @@ namespace winrt::TestComponentCSharp::implementation static hstring GetTypeNameForType(Windows::UI::Xaml::Interop::TypeName const& type); static Windows::Foundation::IInspectable EmptyString(); + static Windows::Foundation::IInspectable BoxedDelegate(); hstring Catch(hstring const& params, hstring& locks); diff --git a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl index f64588208..e3585db6c 100644 --- a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl +++ b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl @@ -379,9 +379,11 @@ namespace TestComponentCSharp static Int32 UnboxInt32(Object obj); static Boolean UnboxBoolean(Object obj); static String UnboxString(Object obj); + static ProvideInt UnboxDelegate(Object obj); static Int32[] UnboxInt32Array(Object obj); static Boolean[] UnboxBooleanArray(Object obj); static String[] UnboxStringArray(Object obj); + static Object BoxedDelegate{ get; }; // WUX.Interop.TypeName -> System.Type mapping static Windows.UI.Xaml.Interop.TypeName Int32Type { get; }; diff --git a/src/Tests/UnitTest/TestComponentCSharp_Tests.cs b/src/Tests/UnitTest/TestComponentCSharp_Tests.cs index 9041a97f1..aec54fa54 100644 --- a/src/Tests/UnitTest/TestComponentCSharp_Tests.cs +++ b/src/Tests/UnitTest/TestComponentCSharp_Tests.cs @@ -2153,6 +2153,9 @@ public void TestValueBoxing() string s = "Hello World!"; Assert.Equal(s, Class.UnboxString(s)); + + ProvideInt intHandler = () => 42; + Assert.Equal(intHandler, Class.UnboxDelegate(intHandler)); } [Fact] @@ -2222,6 +2225,15 @@ public void TestStringUnboxing() Assert.IsType(str2); Assert.Equal(string.Empty, (string)str1); Assert.Equal(string.Empty, (string)str2); + } + + [Fact] + public void TestDelegateUnboxing() + { + var del = Class.BoxedDelegate; + Assert.IsType(del); + var provideUriDel = (ProvideUri) del; + Assert.Equal(new Uri("http://microsoft.com"), provideUriDel()); } internal class ManagedType { } diff --git a/src/Tests/UnitTest/TestComponent_Tests.cs b/src/Tests/UnitTest/TestComponent_Tests.cs index 677d1cf8c..a0513aea6 100644 --- a/src/Tests/UnitTest/TestComponent_Tests.cs +++ b/src/Tests/UnitTest/TestComponent_Tests.cs @@ -974,6 +974,117 @@ public void TestVectorGetMany() Assert.True(composableObjects.GetRange(1, 3).SequenceEqual(interfaceSubset)); } + private void Box_type(T val, Func boxFunc) + { + var boxedVal = boxFunc(val, val); + Assert.IsType(boxedVal); + Assert.Equal((T)boxedVal, val); + } + + [Fact] + public void Box_Byte() + { + Box_type(4, Tests.Box1); + } + + [Fact] + public void Box_UShort() + { + Box_type(4, Tests.Box2); + } + + [Fact] + public void Box_UInt() + { + Box_type(4, Tests.Box3); + } + + [Fact] + public void Box_ULong() + { + Box_type(4, Tests.Box4); + } + + [Fact] + public void Box_Short() + { + Box_type(4, Tests.Box5); + } + + [Fact] + public void Box_Int() + { + Box_type(4, Tests.Box6); + } + + [Fact] + public void Box_Long() + { + Box_type(4, Tests.Box7); + } + + [Fact] + public void Box_Bool() + { + Box_type(true, Tests.Box8); + } + + [Fact] + public void Box_Float() + { + Box_type(4, Tests.Box9); + } + + [Fact] + public void Box_Double() + { + Box_type(4.0, Tests.Box10); + } + + [Fact] + public void Box_Guid() + { + Box_type(Guid.NewGuid(), Tests.Box11); + } + + [Fact] + public void Box_Char() + { + Box_type('c', Tests.Box12); + } + + [Fact] + public void Box_String() + { + Box_type("test", Tests.Box13); + } + + [Fact] + public void Box_Timespan() + { + Box_type(TimeSpan.FromMilliseconds(4), Tests.Box14); + } + + [Fact] + public void Box_Blittable() + { + Blittable blittable = new Blittable(3, 4, 5, 6, 7, 8, 9, 10, 11, typeof(ITests).GUID); + Box_type(blittable, Tests.Box15); + } + + [Fact] + public void Box_NonBittable() + { + NonBlittable nonBlittable = new NonBlittable(true, 'a', "one", 1); + Box_type(nonBlittable, Tests.Box16); + } + + [Fact] + public void Box_DateTime() + { + Box_type(DateTimeOffset.Now, Tests.Box17); + } + // Nota Bene: this test case must always remain the final one [Fact] public void Z_Check_Coverage() diff --git a/src/WinRT.Runtime/ComWrappersSupport.cs b/src/WinRT.Runtime/ComWrappersSupport.cs index da93e9775..9533ed680 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.cs @@ -31,7 +31,8 @@ static partial class ComWrappersSupport { private readonly static ConcurrentDictionary> TypedObjectFactoryCacheForRuntimeClassName = new ConcurrentDictionary>(StringComparer.Ordinal); private readonly static ConcurrentDictionary> TypedObjectFactoryCacheForType = new ConcurrentDictionary>(); - private readonly static ConditionalWeakTable CCWTable = new ConditionalWeakTable(); + private readonly static ConditionalWeakTable CCWTable = new ConditionalWeakTable(); + private readonly static ConcurrentDictionary> DelegateFactoryCache = new ConcurrentDictionary>(); public static TReturn MarshalDelegateInvoke(IntPtr thisPtr, Func invoke) where TDelegate : class, Delegate @@ -154,7 +155,7 @@ internal static List GetInterfaceTableEntries(Type type) Vtable = (IntPtr)ifaceAbiType.GetAbiToProjectionVftblPtr() }); - if(!hasCustomIMarshalInterface && iid == typeof(ABI.WinRT.Interop.IMarshal.Vftbl).GUID) + if (!hasCustomIMarshalInterface && iid == typeof(ABI.WinRT.Interop.IMarshal.Vftbl).GUID) { hasCustomIMarshalInterface = true; } @@ -268,6 +269,11 @@ internal static (InspectableInfo inspectableInfo, List interf private static bool IsNullableT(Type implementationType) { return implementationType.IsGenericType && implementationType.GetGenericTypeDefinition() == typeof(System.Nullable<>); + } + + private static bool IsAbiNullableDelegate(Type implementationType) + { + return implementationType.IsGenericType && implementationType.GetGenericTypeDefinition() == typeof(ABI.System.Nullable_Delegate<>); } private static bool IsIReferenceArray(Type implementationType) @@ -281,21 +287,36 @@ private static Func CreateKeyValuePairFactory(Type type) return Expression.Lambda>( Expression.Call(type.GetHelperType().GetMethod("CreateRcw", BindingFlags.Public | BindingFlags.Static), parms), parms).Compile(); + } + + internal static Func CreateDelegateFactory(Type type) + { + return DelegateFactoryCache.GetOrAdd(type, (type) => + { + var parms = new[] { Expression.Parameter(typeof(IntPtr), "ptr") }; + return Expression.Lambda>( + Expression.Call(type.GetHelperType().GetMethod("CreateRcw", BindingFlags.Public | BindingFlags.Static), + parms), parms).Compile(); + }); } private static Func CreateNullableTFactory(Type implementationType) { Type helperType = implementationType.GetHelperType(); - Type vftblType = helperType.FindVftblType(); ParameterExpression[] parms = new[] { Expression.Parameter(typeof(IInspectable), "inspectable") }; - var createInterfaceInstanceExpression = Expression.New(helperType.GetConstructor(new[] { typeof(ObjectReference<>).MakeGenericType(vftblType) }), - Expression.Call(parms[0], - typeof(IInspectable).GetMethod(nameof(IInspectable.As)).MakeGenericMethod(vftblType))); - return Expression.Lambda>( - Expression.Convert(Expression.Property(createInterfaceInstanceExpression, "Value"), typeof(object)), parms).Compile(); - } + Expression.Convert(Expression.Call(helperType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic), + parms), typeof(object)), parms).Compile(); + } + + private static Func CreateAbiNullableTFactory(Type implementationType) + { + ParameterExpression[] parms = new[] { Expression.Parameter(typeof(IInspectable), "inspectable") }; + return Expression.Lambda>( + Expression.Convert(Expression.Call(implementationType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic), + parms), typeof(object)), parms).Compile(); + } private static Func CreateArrayFactory(Type implementationType) { @@ -369,6 +390,10 @@ internal static Func CreateTypedRcwFactory(Type implementa return CreateReferenceCachingFactory(CreateNullableTFactory(typeof(System.Nullable<>).MakeGenericType(implementationType))); } } + else if (IsAbiNullableDelegate(implementationType)) + { + return CreateReferenceCachingFactory(CreateAbiNullableTFactory(implementationType)); + } else if (IsIReferenceArray(implementationType)) { return CreateReferenceCachingFactory(CreateArrayFactory(implementationType)); @@ -388,11 +413,11 @@ internal static Func CreateTypedRcwFactory(string runtimeC // PropertySet and ValueSet can return IReference but Nullable is illegal if (string.CompareOrdinal(runtimeClassName, "Windows.Foundation.IReference`1") == 0) { - return CreateReferenceCachingFactory((IInspectable obj) => new ABI.System.Nullable(obj.ObjRef)); + return CreateReferenceCachingFactory((IInspectable obj) => ABI.System.Nullable_string.GetValue(obj)); } else if (string.CompareOrdinal(runtimeClassName, "Windows.Foundation.IReference`1") == 0) { - return CreateReferenceCachingFactory((IInspectable obj) => new ABI.System.Nullable(obj.ObjRef)); + return CreateReferenceCachingFactory((IInspectable obj) => ABI.System.Nullable_Type.GetValue(obj)); } Type implementationType = TypeNameSupport.FindTypeByNameCached(runtimeClassName); @@ -476,143 +501,160 @@ private static ComInterfaceEntry ProvideIReference(Type type) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_int.IID, + Vtable = ABI.System.Nullable_int.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(string)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_string.IID, + Vtable = ABI.System.Nullable_string.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(byte)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_byte.IID, + Vtable = ABI.System.Nullable_byte.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(short)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_short.IID, + Vtable = ABI.System.Nullable_short.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(ushort)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_ushort.IID, + Vtable = ABI.System.Nullable_ushort.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(uint)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_uint.IID, + Vtable = ABI.System.Nullable_uint.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(long)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_long.IID, + Vtable = ABI.System.Nullable_long.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(ulong)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_ulong.IID, + Vtable = ABI.System.Nullable_ulong.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(float)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_float.IID, + Vtable = ABI.System.Nullable_float.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(double)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_double.IID, + Vtable = ABI.System.Nullable_double.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(char)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_char.IID, + Vtable = ABI.System.Nullable_char.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(bool)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_bool.IID, + Vtable = ABI.System.Nullable_bool.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(Guid)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_guid.IID, + Vtable = ABI.System.Nullable_guid.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(DateTimeOffset)) { return new ComInterfaceEntry - { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + { + IID = ABI.System.Nullable_DateTimeOffset.IID, + Vtable = ABI.System.Nullable_DateTimeOffset.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(TimeSpan)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_TimeSpan.IID, + Vtable = ABI.System.Nullable_TimeSpan.Vftbl.AbiToProjectionVftablePtr }; } if (type == typeof(object)) { return new ComInterfaceEntry - { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + { + IID = ABI.System.Nullable_Object.IID, + Vtable = ABI.System.Nullable_Object.Vftbl.AbiToProjectionVftablePtr }; - } + } if (type.IsTypeOfType()) + { + return new ComInterfaceEntry + { + IID = ABI.System.Nullable_Type.IID, + Vtable = ABI.System.Nullable_Type.Vftbl.AbiToProjectionVftablePtr + }; + } + if (type == typeof(sbyte)) { return new ComInterfaceEntry { - IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable)), - Vtable = BoxedValueIReferenceImpl.AbiToProjectionVftablePtr + IID = ABI.System.Nullable_sbyte.IID, + Vtable = ABI.System.Nullable_sbyte.Vftbl.AbiToProjectionVftablePtr + }; + } + if (type.IsDelegate()) + { + var delegateHelperType = typeof(ABI.System.Nullable_Delegate<>).MakeGenericType(type); + return new ComInterfaceEntry + { + IID = global::WinRT.GuidGenerator.GetIID(delegateHelperType), + Vtable = delegateHelperType.GetAbiToProjectionVftblPtr() }; } return new ComInterfaceEntry { IID = global::WinRT.GuidGenerator.GetIID(typeof(ABI.System.Nullable<>).MakeGenericType(type)), - Vtable = (IntPtr)typeof(BoxedValueIReferenceImpl<>).MakeGenericType(type).GetAbiToProjectionVftblPtr() + Vtable = typeof(BoxedValueIReferenceImpl<>).MakeGenericType(type).GetAbiToProjectionVftblPtr() }; } diff --git a/src/WinRT.Runtime/ComWrappersSupport.net5.cs b/src/WinRT.Runtime/ComWrappersSupport.net5.cs index b1ba9f3a5..a0478c1e3 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -119,8 +119,7 @@ private static T CreateRcwForComObject(IntPtr ptr, bool tryUseCache) return rcw switch { - ABI.System.Nullable ns => (T)(object)ns.Value, - ABI.System.Nullable nt => (T)(object)nt.Value, + ABI.System.Nullable nt => (T)nt.Value, T castRcw => castRcw, _ when tryUseCache => CreateRcwForComObject(ptr, false), _ => throw new ArgumentException(string.Format("Unable to create a wrapper object. The WinRT object {0} has type {1} which cannot be assigned to type {2}", ptr, rcw.GetType(), typeof(T))) @@ -546,6 +545,10 @@ private static object CreateObject(IntPtr externalComObject) return new SingleInterfaceOptimizedObject(typeof(IWeakReference), iunknownObjRef, false); } + else if (ComWrappersSupport.CreateRCWType != null && ComWrappersSupport.CreateRCWType.IsDelegate()) + { + return ComWrappersSupport.CreateDelegateFactory(ComWrappersSupport.CreateRCWType)(externalComObject); + } else { // If the external COM object isn't IInspectable or IWeakReference, we can't handle it. @@ -556,7 +559,10 @@ private static object CreateObject(IntPtr externalComObject) } finally { - Marshal.Release(ptr); + if (ptr != IntPtr.Zero) + { + Marshal.Release(ptr); + } } } diff --git a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs index 04a02bc56..f52a69c3e 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs @@ -50,7 +50,12 @@ public static T CreateRcwForComObject(IntPtr ptr) else if (identity.TryAs(out var weakRef) == 0) { runtimeWrapper = new ABI.WinRT.Interop.IWeakReference(weakRef); + } + else if (typeof(T).IsDelegate()) + { + runtimeWrapper = CreateDelegateFactory(typeof(T))(ptr); } + keepAliveSentinel = runtimeWrapper; // We don't take a strong reference on runtimeWrapper at any point, so we need to make sure it lives until it can get assigned to rcw. var runtimeWrapperReference = new System.WeakReference(runtimeWrapper); var cleanupSentinel = new RuntimeWrapperCleanup(identity.ThisPtr, runtimeWrapperReference); @@ -80,8 +85,7 @@ public static T CreateRcwForComObject(IntPtr ptr) // for a single System.Type. return rcw switch { - ABI.System.Nullable ns => (T)(object)ns.Value, - ABI.System.Nullable nt => (T)(object)nt.Value, + ABI.System.Nullable nt => (T)nt.Value, _ => (T)rcw }; } diff --git a/src/WinRT.Runtime/Interop/StandardDelegates.cs b/src/WinRT.Runtime/Interop/StandardDelegates.cs index 1c6608827..e0027e064 100644 --- a/src/WinRT.Runtime/Interop/StandardDelegates.cs +++ b/src/WinRT.Runtime/Interop/StandardDelegates.cs @@ -230,5 +230,5 @@ namespace WinRT.Interop #else public #endif - delegate int _remove_EventHandler(IntPtr thisPtr, EventRegistrationToken token); + delegate int _remove_EventHandler(IntPtr thisPtr, EventRegistrationToken token); } diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 71a35f814..a36dfa195 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1260,6 +1260,23 @@ public static IObjectReference CreateMarshaler(object o, Guid delegateIID, bool return ComWrappersSupport.CreateCCWForObject(o, delegateIID); } + + public static T FromAbi(IntPtr nativeDelegate) + where T : System.Delegate + { + if (nativeDelegate == IntPtr.Zero) + { + return null; + } + else if (IUnknownVftbl.IsReferenceToManagedObject(nativeDelegate)) + { + return ComWrappersSupport.FindObject(nativeDelegate); + } + else + { + return ComWrappersSupport.CreateRcwForComObject(nativeDelegate); + } + } } #if EMBED diff --git a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.net5.0.txt b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.net5.0.txt index 8348e50c2..29710890f 100644 --- a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.net5.0.txt +++ b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.net5.0.txt @@ -4,6 +4,9 @@ TypesMustExist : Type 'ABI.System.Collections.Generic.IEnumerableMethods' doe TypesMustExist : Type 'ABI.System.Collections.Generic.IListMethods' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'ABI.System.Collections.Generic.IReadOnlyDictionaryMethods' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'ABI.System.Collections.Generic.IReadOnlyListMethods' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.EventHandler ABI.System.EventHandler.CreateRcw(System.IntPtr)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.Collections.Specialized.NotifyCollectionChangedEventHandler ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.CreateRcw(System.IntPtr)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public System.ComponentModel.PropertyChangedEventHandler ABI.System.ComponentModel.PropertyChangedEventHandler.CreateRcw(System.IntPtr)' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'ABI.WinRT.Interop.IWeakReferenceSourceMethods' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'System.Numerics.VectorExtensions' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'WinRT.ComWrappersHelper' does not exist in the reference but it does exist in the implementation. @@ -11,6 +14,7 @@ MembersMustExist : Member 'public WinRT.ObjectReference WinRT.ComWrappersSupp MembersMustExist : Member 'public void WinRT.ComWrappersSupport.RegisterObjectForInterface(System.Object, System.IntPtr, System.Runtime.InteropServices.CreateObjectFlags)' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'protected void WinRT.IObjectReference.AddRef(System.Boolean)' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public System.Int32 WinRT.IObjectReference.TryAs(System.Guid, System.IntPtr)' does not exist in the reference but it does exist in the implementation. +MembersMustExist : Member 'public T WinRT.MarshalDelegate.FromAbi(System.IntPtr)' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public void WinRT.MarshalString..ctor(System.String)' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public WinRT.MarshalString.Pinnable WinRT.MarshalString.CreatePinnable(System.String)' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public System.IntPtr WinRT.MarshalString.GetAbi()' does not exist in the reference but it does exist in the implementation. @@ -19,4 +23,4 @@ MembersMustExist : Member 'public WinRT.IObjectReference WinRT.MarshalInspectabl TypesMustExist : Type 'WinRT.MarshalString.Pinnable' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'WinRT.Interop.IWeakReference' does not exist in the reference but it does exist in the implementation. TypesMustExist : Type 'WinRT.Interop.IWeakReferenceSource' does not exist in the reference but it does exist in the implementation. -Total Issues: 20 +Total Issues: 24 \ No newline at end of file diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 5d2eef30c..58ff74c39 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -39,6 +39,22 @@ static Projections() RegisterCustomAbiTypeMappingNoLock(typeof(EventRegistrationToken), typeof(ABI.WinRT.EventRegistrationToken), "Windows.Foundation.EventRegistrationToken"); RegisterCustomAbiTypeMappingNoLock(typeof(Nullable<>), typeof(ABI.System.Nullable<>), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_int), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_byte), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_sbyte), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_short), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_ushort), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_uint), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_long), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_ulong), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_float), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_double), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_char), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_bool), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_guid), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_DateTimeOffset), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(Nullable), typeof(ABI.System.Nullable_TimeSpan), "Windows.Foundation.IReference`1"); + RegisterCustomAbiTypeMappingNoLock(typeof(DateTimeOffset), typeof(ABI.System.DateTimeOffset), "Windows.Foundation.DateTime"); RegisterCustomAbiTypeMappingNoLock(typeof(Exception), typeof(ABI.System.Exception), "Windows.Foundation.HResult"); RegisterCustomAbiTypeMappingNoLock(typeof(TimeSpan), typeof(ABI.System.TimeSpan), "Windows.Foundation.TimeSpan"); @@ -124,6 +140,11 @@ public static Type FindCustomHelperTypeMapping(Type publicType, bool filterToRun if (publicType.IsGenericType) { + if (CustomTypeToHelperTypeMappings.TryGetValue(publicType, out Type specializedAbiType)) + { + return specializedAbiType; + } + return CustomTypeToHelperTypeMappings.TryGetValue(publicType.GetGenericTypeDefinition(), out Type abiTypeDefinition) ? abiTypeDefinition.MakeGenericType(publicType.GetGenericArguments()) : null; @@ -143,6 +164,11 @@ public static Type FindCustomPublicTypeForAbiType(Type abiType) { if (abiType.IsGenericType) { + if (CustomAbiTypeToTypeMappings.TryGetValue(abiType, out Type specializedPublicType)) + { + return specializedPublicType; + } + return CustomAbiTypeToTypeMappings.TryGetValue(abiType.GetGenericTypeDefinition(), out Type publicTypeDefinition) ? publicTypeDefinition.MakeGenericType(abiType.GetGenericArguments()) : null; diff --git a/src/WinRT.Runtime/Projections/EventHandler.cs b/src/WinRT.Runtime/Projections/EventHandler.cs index ca0e5ca4f..b4c8aa6ff 100644 --- a/src/WinRT.Runtime/Projections/EventHandler.cs +++ b/src/WinRT.Runtime/Projections/EventHandler.cs @@ -50,9 +50,13 @@ public static IntPtr GetAbi(IObjectReference value) => value is null ? IntPtr.Zero : MarshalInterfaceHelper>.GetAbi(value); public static unsafe global::System.EventHandler FromAbi(IntPtr nativeDelegate) - { - var abiDelegate = ComWrappersSupport.GetObjectReferenceForInterface(nativeDelegate); - return abiDelegate is null ? null : (global::System.EventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.EventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate); + { + return MarshalDelegate.FromAbi>(nativeDelegate); + } + + public static global::System.EventHandler CreateRcw(IntPtr ptr) + { + return new global::System.EventHandler(new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr)).Invoke); } [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] @@ -61,34 +65,34 @@ private sealed class NativeDelegateWrapper #else private sealed class NativeDelegateWrapper : IWinRTObject #endif - { + { private readonly ObjectReference _nativeDelegate; public NativeDelegateWrapper(ObjectReference nativeDelegate) - { + { _nativeDelegate = nativeDelegate; - } - + } + #if NET - IObjectReference IWinRTObject.NativeObject => _nativeDelegate; - bool IWinRTObject.HasUnwrappableNativeObject => true; + IObjectReference IWinRTObject.NativeObject => _nativeDelegate; + bool IWinRTObject.HasUnwrappableNativeObject => true; private volatile ConcurrentDictionary _queryInterfaceCache; private ConcurrentDictionary MakeQueryInterfaceCache() - { + { global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); - return _queryInterfaceCache; - } + return _queryInterfaceCache; + } ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); private volatile ConcurrentDictionary _additionalTypeData; private ConcurrentDictionary MakeAdditionalTypeData() - { + { global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); - return _additionalTypeData; - } + return _additionalTypeData; + } ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); #endif - + public void Invoke(object sender, T args) { IntPtr ThisPtr = _nativeDelegate.ThisPtr; @@ -109,7 +113,6 @@ public void Invoke(object sender, T args) MarshalInspectable.DisposeMarshaler(__sender); Marshaler.DisposeMarshaler(__args); } - } } @@ -180,45 +183,49 @@ public static IntPtr GetAbi(IObjectReference value) => value is null ? IntPtr.Zero : MarshalInterfaceHelper>.GetAbi(value); public static unsafe global::System.EventHandler FromAbi(IntPtr nativeDelegate) - { - var abiDelegate = ComWrappersSupport.GetObjectReferenceForInterface(nativeDelegate); - return abiDelegate is null ? null : (global::System.EventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.EventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate); - } - + { + return MarshalDelegate.FromAbi(nativeDelegate); + } + + public static global::System.EventHandler CreateRcw(IntPtr ptr) + { + return new global::System.EventHandler(new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr)).Invoke); + } + [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET private sealed class NativeDelegateWrapper #else private sealed class NativeDelegateWrapper : IWinRTObject #endif - { + { private readonly ObjectReference _nativeDelegate; public NativeDelegateWrapper(ObjectReference nativeDelegate) - { + { _nativeDelegate = nativeDelegate; - } - + } + #if NET - IObjectReference IWinRTObject.NativeObject => _nativeDelegate; - bool IWinRTObject.HasUnwrappableNativeObject => true; + IObjectReference IWinRTObject.NativeObject => _nativeDelegate; + bool IWinRTObject.HasUnwrappableNativeObject => true; private volatile ConcurrentDictionary _queryInterfaceCache; private ConcurrentDictionary MakeQueryInterfaceCache() - { + { global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new ConcurrentDictionary(), null); - return _queryInterfaceCache; - } + return _queryInterfaceCache; + } ConcurrentDictionary IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache(); private volatile ConcurrentDictionary _additionalTypeData; private ConcurrentDictionary MakeAdditionalTypeData() - { + { global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new ConcurrentDictionary(), null); - return _additionalTypeData; - } + return _additionalTypeData; + } ConcurrentDictionary IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData(); #endif - + public unsafe void Invoke(object sender, EventArgs args) { IntPtr ThisPtr = _nativeDelegate.ThisPtr; diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs index 025aef452..2cdaee604 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs @@ -51,9 +51,13 @@ public static unsafe IObjectReference CreateMarshaler(global::System.Collections public static IntPtr GetAbi(IObjectReference value) => MarshalInterfaceHelper.GetAbi(value); public static unsafe global::System.Collections.Specialized.NotifyCollectionChangedEventHandler FromAbi(IntPtr nativeDelegate) - { - var abiDelegate = ComWrappersSupport.GetObjectReferenceForInterface(nativeDelegate); - return abiDelegate is null ? null : (global::System.Collections.Specialized.NotifyCollectionChangedEventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.Collections.Specialized.NotifyCollectionChangedEventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate); + { + return MarshalDelegate.FromAbi(nativeDelegate); + } + + public static global::System.Collections.Specialized.NotifyCollectionChangedEventHandler CreateRcw(IntPtr ptr) + { + return new global::System.Collections.Specialized.NotifyCollectionChangedEventHandler(new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr)).Invoke); } [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] diff --git a/src/WinRT.Runtime/Projections/Nullable.cs b/src/WinRT.Runtime/Projections/Nullable.cs index 131902fe4..eb2e86287 100644 --- a/src/WinRT.Runtime/Projections/Nullable.cs +++ b/src/WinRT.Runtime/Projections/Nullable.cs @@ -126,10 +126,16 @@ internal unsafe Vftbl(IntPtr thisPtr) public IntPtr ThisPtr => _obj.ThisPtr; public ObjectReference AsInterface() => _obj.As(); public A As() => _obj.AsType(); - public Nullable(IObjectReference obj) : this(obj.As()) { } + public Nullable(IObjectReference obj) : this(obj.As(Vftbl.PIID)) { } public Nullable(ObjectReference obj) { _obj = obj; + } + + internal static T GetValue(IInspectable inspectable) + { + var nullable = new Nullable(inspectable.ObjRef); + return nullable.Value; } public unsafe T Value @@ -148,5 +154,1467 @@ public unsafe T Value } } } + } + + // Used to handle boxing of strings and types where the C# compiler will de-duplicate them + // causing for the same instance to be reused with multiple different box instances. + // This is also used for delegates which are objects themselves in C# and are associated with + // their own ptr and thereby can not be associated with the ptr for the box / nullable. + internal sealed class Nullable + { + public Nullable(object boxedObject) + { + Value = boxedObject; + } + + public object Value { get; } + } + + [Guid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")] + internal static class Nullable_int + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i4)"; + internal static Guid IID = new(0x548cefbd, 0xbc8a, 0x5fa0, 0x8d, 0xf2, 0x95, 0x74, 0x40, 0xfc, 0x8b, 0xf4); + + [Guid("548cefbd-bc8a-5fa0-8df2-957440fc8bf4")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, int* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, int* __return_value__) + { + int ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (int)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static int GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + int __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("fd416dfb-2a07-52eb-aae3-dfce14116c05")] + internal static class Nullable_string + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};string)"; + internal static Guid IID = new(0xfd416dfb, 0x2a07, 0x52eb, 0xaa, 0xe3, 0xdf, 0xce, 0x14, 0x11, 0x6c, 0x05); + + [Guid("fd416dfb-2a07-52eb-aae3-dfce14116c05")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, IntPtr* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) + { + string ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (string)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = MarshalString.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static Nullable GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + IntPtr __retval = default; + try + { + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return new Nullable(MarshalString.FromAbi(__retval)); + } + finally + { + MarshalString.DisposeAbi(__retval); + Marshal.Release(nullablePtr); + } + } + } + + [Guid("e5198cc8-2873-55f5-b0a1-84ff9e4aad62")] + internal static class Nullable_byte + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u1)"; + internal static Guid IID = new(0xe5198cc8, 0x2873, 0x55f5, 0xb0, 0xa1, 0x84, 0xff, 0x9e, 0x4a, 0xad, 0x62); + + [Guid("e5198cc8-2873-55f5-b0a1-84ff9e4aad62")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, byte* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, byte* __return_value__) + { + byte ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (byte)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static byte GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + byte __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("95500129-fbf6-5afc-89df-70642d741990")] + internal static class Nullable_sbyte + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i1)"; + internal static Guid IID = new(0x95500129, 0xfbf6, 0x5afc, 0x89, 0xdf, 0x70, 0x64, 0x2d, 0x74, 0x19, 0x90); + + [Guid("95500129-fbf6-5afc-89df-70642d741990")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, sbyte* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, sbyte* __return_value__) + { + sbyte ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (sbyte)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static sbyte GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + sbyte __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("6ec9e41b-6709-5647-9918-a1270110fc4e")] + internal static class Nullable_short + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i2)"; + internal static Guid IID = new(0x6ec9e41b, 0x6709, 0x5647, 0x99, 0x18, 0xa1, 0x27, 0x01, 0x10, 0xfc, 0x4e); + + [Guid("6ec9e41b-6709-5647-9918-a1270110fc4e")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, short* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, short* __return_value__) + { + short ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (short)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static short GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + short __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("5ab7d2c3-6b62-5e71-a4b6-2d49c4f238fd")] + internal static class Nullable_ushort + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u2)"; + internal static Guid IID = new(0x5ab7d2c3, 0x6b62, 0x5e71, 0xa4, 0xb6, 0x2d, 0x49, 0xc4, 0xf2, 0x38, 0xfd); + + [Guid("5ab7d2c3-6b62-5e71-a4b6-2d49c4f238fd")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, ushort* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, ushort* __return_value__) + { + ushort ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (ushort)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static ushort GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + ushort __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("513ef3af-e784-5325-a91e-97c2b8111cf3")] + internal static class Nullable_uint + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u4)"; + internal static Guid IID = new(0x513ef3af, 0xe784, 0x5325, 0xa9, 0x1e, 0x97, 0xc2, 0xb8, 0x11, 0x1c, 0xf3); + + [Guid("513ef3af-e784-5325-a91e-97c2b8111cf3")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, uint* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, uint* __return_value__) + { + uint ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (uint)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static uint GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + uint __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("4dda9e24-e69f-5c6a-a0a6-93427365af2a")] + internal static class Nullable_long + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};i8)"; + internal static Guid IID = new(0x4dda9e24, 0xe69f, 0x5c6a, 0xa0, 0xa6, 0x93, 0x42, 0x73, 0x65, 0xaf, 0x2a); + + [Guid("4dda9e24-e69f-5c6a-a0a6-93427365af2a")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, long* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, long* __return_value__) + { + long ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (long)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static long GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + long __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("6755e376-53bb-568b-a11d-17239868309e")] + internal static class Nullable_ulong + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};u8)"; + internal static Guid IID = new(0x6755e376, 0x53bb, 0x568b, 0xa1, 0x1d, 0x17, 0x23, 0x98, 0x68, 0x30, 0x9e); + + [Guid("6755e376-53bb-568b-a11d-17239868309e")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, ulong* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, ulong* __return_value__) + { + ulong ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (ulong)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static ulong GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + ulong __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("719cc2ba-3e76-5def-9f1a-38d85a145ea8")] + internal static class Nullable_float + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};f4)"; + internal static Guid IID = new(0x719cc2ba, 0x3e76, 0x5def, 0x9f, 0x1a, 0x38, 0xd8, 0x5a, 0x14, 0x5e, 0xa8); + + [Guid("719cc2ba-3e76-5def-9f1a-38d85a145ea8")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, float* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, float* __return_value__) + { + float ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (float)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static float GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + float __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("2f2d6c29-5473-5f3e-92e7-96572bb990e2")] + internal static class Nullable_double + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};f8)"; + internal static Guid IID = new(0x2f2d6c29, 0x5473, 0x5f3e, 0x92, 0xe7, 0x96, 0x57, 0x2b, 0xb9, 0x90, 0xe2); + + [Guid("2f2d6c29-5473-5f3e-92e7-96572bb990e2")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, double* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, double* __return_value__) + { + double ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (double)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static double GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + double __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("fb393ef3-bbac-5bd5-9144-84f23576f415")] + internal static class Nullable_char + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};c2)"; + internal static Guid IID = new(0xfb393ef3, 0xbbac, 0x5bd5, 0x91, 0x44, 0x84, 0xf2, 0x35, 0x76, 0xf4, 0x15); + + [Guid("fb393ef3-bbac-5bd5-9144-84f23576f415")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, char* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, char* __return_value__) + { + char ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (char)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static char GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + char __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")] + internal static class Nullable_bool + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};b1)"; + internal static Guid IID = new(0x3c00fd60, 0x2950, 0x5939, 0xa2, 0x1a, 0x2d, 0x12, 0xc5, 0xa0, 0x1b, 0x8a); + + [Guid("3c00fd60-2950-5939-a21a-2d12c5a01b8a")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, bool* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, bool* __return_value__) + { + bool ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (bool)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static bool GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + bool __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("7d50f649-632c-51f9-849a-ee49428933ea")] + internal static class Nullable_guid + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};g16)"; + internal static Guid IID = new(0x7d50f649, 0x632c, 0x51f9, 0x84, 0x9a, 0xee, 0x49, 0x42, 0x89, 0x33, 0xea); + + [Guid("7d50f649-632c-51f9-849a-ee49428933ea")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, Guid* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, Guid* __return_value__) + { + Guid ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (Guid)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = ____return_value__; + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static Guid GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + try + { + Guid __retval = default; + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return __retval; + } + finally + { + Marshal.Release(nullablePtr); + } + } + } + + [Guid("5541d8a7-497c-5aa4-86fc-7713adbf2a2c")] + internal static class Nullable_DateTimeOffset + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.DateTime;i8))"; + internal static Guid IID = new(0x5541d8a7, 0x497c, 0x5aa4, 0x86, 0xfc, 0x77, 0x13, 0xad, 0xbf, 0x2a, 0x2c); + + [Guid("5541d8a7-497c-5aa4-86fc-7713adbf2a2c")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, DateTimeOffset* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, DateTimeOffset* __return_value__) + { + global::System.DateTimeOffset ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (global::System.DateTimeOffset)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = DateTimeOffset.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static global::System.DateTimeOffset GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + DateTimeOffset __retval = default; + try + { + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return DateTimeOffset.FromAbi(__retval); + } + finally + { + DateTimeOffset.DisposeAbi(__retval); + Marshal.Release(nullablePtr); + } + } + } + + [Guid("604d0c4c-91de-5c2a-935f-362f13eaf800")] + internal static class Nullable_TimeSpan + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.Foundation.TimeSpan;i8))"; + internal static Guid IID = new(0x604d0c4c, 0x91de, 0x5c2a, 0x93, 0x5f, 0x36, 0x2f, 0x13, 0xea, 0xf8, 0x00); + + [Guid("604d0c4c-91de-5c2a-935f-362f13eaf800")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, TimeSpan* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, TimeSpan* __return_value__) + { + global::System.TimeSpan ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (global::System.TimeSpan)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = TimeSpan.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static global::System.TimeSpan GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + TimeSpan __retval = default; + try + { + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return TimeSpan.FromAbi(__retval); + } + finally + { + TimeSpan.DisposeAbi(__retval); + Marshal.Release(nullablePtr); + } + } + } + + [Guid("06dccc90-a058-5c88-87b7-6f3360a2fc16")] + internal static class Nullable_Object + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};cinterface(IInspectable))"; + internal static Guid IID = new(0x06dccc90, 0xa058, 0x5c88, 0x87, 0xb7, 0x6f, 0x33, 0x60, 0xa2, 0xfc, 0x16); + + [Guid("06dccc90-a058-5c88-87b7-6f3360a2fc16")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, IntPtr* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) + { + object ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = MarshalInspectable.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + } + + [Guid("3830ad99-d8da-53f3-989b-fc92ad222778")] + internal static class Nullable_Type + { + public static string GetGuidSignature() => "pinterface({61c17706-2d65-11e0-9ae8-d48564015472};struct(Windows.UI.Xaml.Interop.TypeName;string;enum(Windows.UI.Xaml.Interop.TypeKind;i4)))"; + internal static Guid IID = new(0x3830ad99, 0xd8da, 0x53f3, 0x98, 0x9b, 0xfc, 0x92, 0xad, 0x22, 0x27, 0x78); + + [Guid("3830ad99-d8da-53f3-989b-fc92ad222778")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private void* _Get_Value_0; + public delegate* unmanaged[Stdcall] Get_Value_0 { get => (delegate* unmanaged[Stdcall])_Get_Value_0; set => _Get_Value_0 = value; } + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + +#if NETSTANDARD2_0 + private unsafe delegate int GetValueDelegate(IntPtr thisPtr, Type* value); + private static readonly GetValueDelegate delegateCache; +#endif + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, +#if NETSTANDARD2_0 + _Get_Value_0 = Marshal.GetFunctionPointerForDelegate(delegateCache = Do_Abi_get_Value_0).ToPointer() +#else + _Get_Value_0 = (delegate* unmanaged)&Do_Abi_get_Value_0 +#endif + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + +#if !NETSTANDARD2_0 + [UnmanagedCallersOnly] +#endif + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, Type* __return_value__) + { + global::System.Type ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = (global::System.Type)global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = Type.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + unsafe internal static Nullable GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + Type __retval = default; + try + { + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref IID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return new Nullable(Type.FromAbi(__retval)); + } + finally + { + Type.DisposeAbi(__retval); + Marshal.Release(nullablePtr); + } + } + } + + [Guid("61C17706-2D65-11E0-9AE8-D48564015472")] + internal static class Nullable_Delegate where T : global::System.Delegate + { + public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(Nullable)); + + [Guid("61C17706-2D65-11E0-9AE8-D48564015472")] + public unsafe struct Vftbl + { + internal IInspectable.Vftbl IInspectableVftbl; + private Nullable_Delegates.GetValueDelegate _Get_Value_0; + + public static Guid PIID = GuidGenerator.CreateIID(typeof(Nullable)); + + private static readonly Vftbl AbiToProjectionVftable; + public static readonly IntPtr AbiToProjectionVftablePtr; + + static Vftbl() + { + AbiToProjectionVftable = new Vftbl + { + IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable, + _Get_Value_0 = Do_Abi_get_Value_0 + }; + var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), Marshal.SizeOf() + sizeof(IntPtr) * 1); + Marshal.StructureToPtr(AbiToProjectionVftable.IInspectableVftbl, (IntPtr)nativeVftbl, false); + nativeVftbl[6] = Marshal.GetFunctionPointerForDelegate(AbiToProjectionVftable._Get_Value_0); + AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; + } + + private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, IntPtr* __return_value__) + { + T ____return_value__ = default; + + *__return_value__ = default; + + try + { + ____return_value__ = global::WinRT.ComWrappersSupport.FindObject(thisPtr); + *__return_value__ = (IntPtr)Marshaler.FromManaged(____return_value__); + } + catch (global::System.Exception __exception__) + { + global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); + return global::WinRT.ExceptionHelpers.GetHRForException(__exception__); + } + return 0; + } + } + + public static Guid PIID = Vftbl.PIID; + + unsafe internal static Nullable GetValue(IInspectable inspectable) + { + IntPtr nullablePtr = IntPtr.Zero; + IntPtr __retval = default; + try + { + ExceptionHelpers.ThrowExceptionForHR(Marshal.QueryInterface(inspectable.ThisPtr, ref PIID, out nullablePtr)); + ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]**)nullablePtr)[6](nullablePtr, &__retval)); + return new Nullable(Marshaler.FromAbi(__retval)); + } + finally + { + Marshaler.DisposeAbi(__retval); + Marshal.Release(nullablePtr); + } + } + } + + internal static class Nullable_Delegates + { + public unsafe delegate int GetValueDelegate(IntPtr thisPtr, IntPtr* value); } } diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs index 998846cc8..328e27a17 100644 --- a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs @@ -50,9 +50,13 @@ public static unsafe IObjectReference CreateMarshaler(global::System.ComponentMo public static IntPtr GetAbi(IObjectReference value) => MarshalInterfaceHelper.GetAbi(value); public static unsafe global::System.ComponentModel.PropertyChangedEventHandler FromAbi(IntPtr nativeDelegate) - { - var abiDelegate = ComWrappersSupport.GetObjectReferenceForInterface(nativeDelegate); - return abiDelegate is null ? null : (global::System.ComponentModel.PropertyChangedEventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.ComponentModel.PropertyChangedEventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate); + { + return MarshalDelegate.FromAbi(nativeDelegate); + } + + public static global::System.ComponentModel.PropertyChangedEventHandler CreateRcw(IntPtr ptr) + { + return new global::System.ComponentModel.PropertyChangedEventHandler(new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr)).Invoke); } [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] diff --git a/src/WinRT.Runtime/TypeNameSupport.cs b/src/WinRT.Runtime/TypeNameSupport.cs index 554862dac..8b46bc0df 100644 --- a/src/WinRT.Runtime/TypeNameSupport.cs +++ b/src/WinRT.Runtime/TypeNameSupport.cs @@ -133,6 +133,10 @@ private static Type FindTypeByNameCore(string runtimeClassName, Type[] genericTy { if (genericTypes != null) { + if(resolvedType == typeof(global::System.Nullable<>) && genericTypes[0].IsDelegate()) + { + return typeof(ABI.System.Nullable_Delegate<>).MakeGenericType(genericTypes); + } resolvedType = resolvedType.MakeGenericType(genericTypes); } return resolvedType; @@ -155,7 +159,8 @@ public static Type ResolvePrimitiveType(string primitiveTypeName) "Int64" => typeof(long), "Boolean" => typeof(bool), "String" => typeof(string), - "Char" => typeof(char), + "Char" => typeof(char), + "Char16" => typeof(char), "Single" => typeof(float), "Double" => typeof(double), "Guid" => typeof(Guid), diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index 551e497ab..a4f748821 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -6559,8 +6559,12 @@ public static IntPtr GetAbi(IObjectReference value) => MarshalInterfaceHelper<%> public static unsafe % FromAbi(IntPtr nativeDelegate) { -var abiDelegate = ComWrappersSupport.GetObjectReferenceForInterface(nativeDelegate); -return abiDelegate is null ? null : (%)ComWrappersSupport.TryRegisterObjectForInterface(new %(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate); +return MarshalDelegate.FromAbi<%>(nativeDelegate); +} + +public static % CreateRcw(IntPtr ptr) +{ +return new %(new NativeDelegateWrapper(ComWrappersSupport.GetObjectReferenceForInterface(ptr)).Invoke); } [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] @@ -6696,6 +6700,7 @@ public static Guid PIID = GuidGenerator.CreateIID(typeof(%));)", type_name, type_name, type_name, + type_name, // NativeDelegateWrapper.Invoke bind(signature), bind_list(", ", signature.params()), diff --git a/src/cswinrt/strings/WinRT_Interop.cs b/src/cswinrt/strings/WinRT_Interop.cs index ad5e06b11..38266aed5 100644 --- a/src/cswinrt/strings/WinRT_Interop.cs +++ b/src/cswinrt/strings/WinRT_Interop.cs @@ -18,14 +18,14 @@ internal unsafe struct IActivationFactoryVftbl public delegate* unmanaged[Stdcall] ActivateInstance => (delegate* unmanaged[Stdcall])_ActivateInstance; internal static readonly Guid IID = new(0x00000035, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46); - } - - // IDelegate + } + + // IDelegate internal struct IDelegateVftbl { public IUnknownVftbl IUnknownVftbl; public IntPtr Invoke; - } + } [Guid("64BD43F8-bFEE-4EC4-B7EB-2935158DAE21")] [StructLayout(LayoutKind.Sequential)] diff --git a/src/get_testwinrt.cmd b/src/get_testwinrt.cmd index 926294725..18c769731 100644 --- a/src/get_testwinrt.cmd +++ b/src/get_testwinrt.cmd @@ -14,7 +14,7 @@ git checkout -f master if ErrorLevel 1 popd & exit /b !ErrorLevel! git fetch -f if ErrorLevel 1 popd & exit /b !ErrorLevel! -git reset -q --hard d448f7cf94b5376b2ef7af9ad78b7c5077ff0473 +git reset -q --hard c08bbd40da7f93e29ca2ed683e32121a4692535d if ErrorLevel 1 popd & exit /b !ErrorLevel! echo Restoring Nuget %this_dir%.nuget\nuget.exe restore