Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        private static unsafe IGlobalInterfaceTable GetGitTable()
        {
            Guid   gitClsid = CLSID_StdGlobalInterfaceTable;
            Guid   gitIid   = typeof(IGlobalInterfaceTable).GUID;
            IntPtr gitPtr   = default;

            try
            {
                Marshal.ThrowExceptionForHR(Platform.CoCreateInstance(
                                                ref gitClsid,
                                                IntPtr.Zero,
                                                1 /*CLSCTX_INPROC_SERVER*/,
                                                ref gitIid,
                                                &gitPtr));
                return(ABI.WinRT.Interop.IGlobalInterfaceTable.FromAbi(gitPtr).AsType <ABI.WinRT.Interop.IGlobalInterfaceTable>());
            }
            finally
            {
                MarshalInterface <IGlobalInterfaceTable> .DisposeAbi(gitPtr);
            }
        }