Пример #1
0
 public ObjectReference <T> As <T>(Guid iid)
 {
     ThrowIfDisposed();
     Marshal.ThrowExceptionForHR(VftblIUnknown.QueryInterface(ThisPtr, ref iid, out IntPtr thatPtr));
     return(ObjectReference <T> .Attach(ref thatPtr));
 }
Пример #2
0
 public int TryAs <T>(out ObjectReference <T> objRef) => TryAs <T>(GuidGenerator.GetIID(typeof(T)), out objRef);
Пример #3
0
        public unsafe AgileReference(IObjectReference instance)
        {
            if (instance?.ThisPtr == null)
            {
                return;
            }

            IntPtr agileReference = default;
            Guid   iid            = typeof(IUnknownVftbl).GUID;

            try
            {
                Marshal.ThrowExceptionForHR(Platform.RoGetAgileReference(
                                                0 /*AGILEREFERENCE_DEFAULT*/,
                                                ref iid,
                                                instance.ThisPtr,
                                                &agileReference));
#if NET5_0
                _agileReference = (IAgileReference) new SingleInterfaceOptimizedObject(typeof(IAgileReference), ObjectReference <ABI.WinRT.Interop.IAgileReference.Vftbl> .Attach(ref agileReference));
#else
                _agileReference = ABI.WinRT.Interop.IAgileReference.FromAbi(agileReference).AsType <ABI.WinRT.Interop.IAgileReference>();
#endif
            }
            catch (TypeLoadException)
            {
                _cookie = Git.Value.RegisterInterfaceInGlobal(instance, iid);
            }
            finally
            {
                MarshalInterface <IAgileReference> .DisposeAbi(agileReference);
            }
        }