diff --git a/src/WinRT.Runtime/ComWrappersSupport.cs b/src/WinRT.Runtime/ComWrappersSupport.cs index d39eda7d4..118c057ef 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.cs @@ -89,11 +89,11 @@ unsafe static bool IsFreeThreaded(IObjectReference unknownRef) Marshal.Release(agilePtr); return true; } - else if (unknownRef.TryAs(out var marshalRef) >= 0) + else if (unknownRef.TryAs(ABI.WinRT.Interop.IMarshal.IID, out var marshalRef) >= 0) { using (marshalRef) { - Guid iid_IUnknown = typeof(IUnknownVftbl).GUID; + Guid iid_IUnknown = IUnknownVftbl.IID; Guid iid_unmarshalClass; Marshal.ThrowExceptionForHR(marshalRef.Vftbl.GetUnmarshalClass_0( marshalRef.ThisPtr, &iid_IUnknown, IntPtr.Zero, MSHCTX.InProc, IntPtr.Zero, MSHLFLAGS.Normal, &iid_unmarshalClass)); diff --git a/src/WinRT.Runtime/ComWrappersSupport.net5.cs b/src/WinRT.Runtime/ComWrappersSupport.net5.cs index aa684bc9b..c71198067 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -229,7 +229,7 @@ public unsafe static void Init( // otherwise the new instance will be used. Since the inner was composed // it should answer immediately without going through the outer. Either way // the reference count will go to the new instance. - Guid iid = typeof(IReferenceTrackerVftbl).GUID; + Guid iid = IReferenceTrackerVftbl.IID; int hr = Marshal.QueryInterface(objRef.ThisPtr, ref iid, out referenceTracker); if (hr != 0) { @@ -330,7 +330,7 @@ public unsafe static void Init(IObjectReference objRef, bool addRefFromTrackerSo { if (objRef.ReferenceTrackerPtr == IntPtr.Zero) { - Guid iid = typeof(IReferenceTrackerVftbl).GUID; + Guid iid = IReferenceTrackerVftbl.IID; int hr = Marshal.QueryInterface(objRef.ThisPtr, ref iid, out var referenceTracker); if (hr == 0) { @@ -434,7 +434,7 @@ private static unsafe bool IsRuntimeImplementedRCW(Type objType) private static object CreateObject(IObjectReference objRef) { - if (objRef.TryAs(out var inspectableRef) == 0) + if (objRef.TryAs(IInspectable.IID, out var inspectableRef) == 0) { IInspectable inspectable = new IInspectable(inspectableRef); @@ -448,7 +448,7 @@ private static object CreateObject(IObjectReference objRef) return ComWrappersSupport.GetTypedRcwFactory(runtimeClassName)(inspectable); } - else if (objRef.TryAs(out var weakRef) == 0) + else if (objRef.TryAs(ABI.WinRT.Interop.IWeakReference.IID, out var weakRef) == 0) { // IWeakReference is IUnknown-based, so implementations of it may not (and likely won't) implement // IInspectable. As a result, we need to check for them explicitly. diff --git a/src/WinRT.Runtime/IInspectable.cs b/src/WinRT.Runtime/IInspectable.cs index fbcadf9ef..308e6ddfd 100644 --- a/src/WinRT.Runtime/IInspectable.cs +++ b/src/WinRT.Runtime/IInspectable.cs @@ -17,7 +17,9 @@ public enum TrustLevel [ObjectReferenceWrapper(nameof(_obj))] [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] public partial class IInspectable - { + { + internal static readonly Guid IID = Guid.Parse("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90"); + [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] public unsafe struct Vftbl { diff --git a/src/WinRT.Runtime/Interop/IMarshal.cs b/src/WinRT.Runtime/Interop/IMarshal.cs index ff0054bfe..59789b624 100644 --- a/src/WinRT.Runtime/Interop/IMarshal.cs +++ b/src/WinRT.Runtime/Interop/IMarshal.cs @@ -31,7 +31,9 @@ namespace ABI.WinRT.Interop { [Guid("00000003-0000-0000-c000-000000000046")] internal class IMarshal - { + { + internal static readonly Guid IID = Guid.Parse("00000003-0000-0000-c000-000000000046"); + [DllImport("api-ms-win-core-com-l1-1-0.dll")] private static extern int CoCreateFreeThreadedMarshaler(IntPtr outer, out IntPtr marshalerPtr); diff --git a/src/WinRT.Runtime/Interop/IReferenceTracker.cs b/src/WinRT.Runtime/Interop/IReferenceTracker.cs index 4eb61e8bf..0647061ac 100644 --- a/src/WinRT.Runtime/Interop/IReferenceTracker.cs +++ b/src/WinRT.Runtime/Interop/IReferenceTracker.cs @@ -16,5 +16,7 @@ internal unsafe struct IReferenceTrackerVftbl private void* _ReleaseFromTrackerSource_5; public delegate* unmanaged[Stdcall] ReleaseFromTrackerSource { get => (delegate* unmanaged[Stdcall])_ReleaseFromTrackerSource_5; set => _ReleaseFromTrackerSource_5 = (void*)value; } private void* _PegFromTrackerSource_6; + + internal static readonly Guid IID = Guid.Parse("11D3B13A-180E-4789-A8BE-7712882893E6"); } } \ No newline at end of file diff --git a/src/WinRT.Runtime/Interop/IUnknownVftbl.cs b/src/WinRT.Runtime/Interop/IUnknownVftbl.cs index 8a81c4c0a..6fd51be83 100644 --- a/src/WinRT.Runtime/Interop/IUnknownVftbl.cs +++ b/src/WinRT.Runtime/Interop/IUnknownVftbl.cs @@ -16,6 +16,8 @@ public unsafe struct IUnknownVftbl public delegate* unmanaged[Stdcall] Release { get => (delegate* unmanaged[Stdcall])_Release; set => _Release = (void*)value; } public static IUnknownVftbl AbiToProjectionVftbl => ComWrappersSupport.IUnknownVftbl; - public static IntPtr AbiToProjectionVftblPtr => ComWrappersSupport.IUnknownVftblPtr; + public static IntPtr AbiToProjectionVftblPtr => ComWrappersSupport.IUnknownVftblPtr; + + internal static readonly Guid IID = Guid.Parse("00000000-0000-0000-C000-000000000046"); } } diff --git a/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs b/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs index 42219959e..55d9f42a3 100644 --- a/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs +++ b/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs @@ -117,7 +117,9 @@ private static int Do_Abi_GetWeakReference(IntPtr thisPtr, IntPtr* weakReference [DynamicInterfaceCastableImplementation] [Guid("00000037-0000-0000-C000-000000000046")] internal unsafe interface IWeakReference : global::WinRT.Interop.IWeakReference - { + { + internal static readonly Guid IID = Guid.Parse("00000037-0000-0000-C000-000000000046"); + [Guid("00000037-0000-0000-C000-000000000046")] public struct Vftbl { diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 621b356cd..9801b8463 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1038,7 +1038,7 @@ public static IObjectReference CreateMarshaler(T o, bool unwrapObject = true) if (unwrapObject && ComWrappersSupport.TryUnwrapObject(o, out var objRef)) { - return objRef.As(); + return objRef.As(IInspectable.IID); } var publicType = o.GetType(); Type helperType = Projections.FindCustomHelperTypeMapping(publicType, true); @@ -1052,7 +1052,7 @@ public static IObjectReference CreateMarshaler(T o, bool unwrapObject = true) } using (var ccw = ComWrappersSupport.CreateCCWForObject(o)) { - return ccw.As(); + return ccw.As(IInspectable.IID); } } @@ -1066,7 +1066,7 @@ public static T FromAbi(IntPtr ptr) return default; } using var objRef = ObjectReference.FromAbi(ptr); - using var unknownObjRef = objRef.As(); + using var unknownObjRef = objRef.As(IUnknownVftbl.IID); if (unknownObjRef.IsReferenceToManagedObject) { return (T) ComWrappersSupport.FindObject(unknownObjRef.ThisPtr); diff --git a/src/WinRT.Runtime/Projections.cs b/src/WinRT.Runtime/Projections.cs index 3102e26ad..e8cbd554d 100644 --- a/src/WinRT.Runtime/Projections.cs +++ b/src/WinRT.Runtime/Projections.cs @@ -402,7 +402,7 @@ internal static bool TryGetMarshalerTypeForProjectedRuntimeClass(IObjectRefer Type projectedType = typeof(T); if (projectedType == typeof(object)) { - if (objectReference.TryAs(out var inspectablePtr) == 0) + if (objectReference.TryAs(IInspectable.IID, out var inspectablePtr) == 0) { rwlock.EnterReadLock(); try