Ejemplo n.º 1
0
        public unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId)
        {
            IntPtr instancePtr;
            var    hstrRuntimeClassId = MarshalString.CreateMarshaler(runtimeClassId);
            int    hr = _GetActivationFactory(MarshalString.GetAbi(hstrRuntimeClassId), out instancePtr);

            return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr);
        }
Ejemplo n.º 2
0
        public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId)
        {
            var    module = Instance; // Ensure COM is initialized
            Guid   iid    = typeof(IActivationFactoryVftbl).GUID;
            IntPtr instancePtr;
            var    hstrRuntimeClassId = MarshalString.CreateMarshaler(runtimeClassId);
            int    hr = Platform.RoGetActivationFactory(MarshalString.GetAbi(hstrRuntimeClassId), ref iid, &instancePtr);

            return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr);
        }
Ejemplo n.º 3
0
        public virtual unsafe int TryAs <T>(Guid iid, out ObjectReference <T> objRef)
        {
            objRef = null;
            ThrowIfDisposed();
            int hr = VftblIUnknown.QueryInterface(ThisPtr, ref iid, out IntPtr thatPtr);

            if (hr >= 0)
            {
                objRef = ObjectReference <T> .Attach(ref thatPtr);
            }
            return(hr);
        }
Ejemplo n.º 4
0
        protected override unsafe void Release()
        {
            ComCallData data = default;
            IntPtr      contextCallbackPtr = _contextCallbackPtr;

            var contextCallback = new ABI.WinRT.Interop.IContextCallback(ObjectReference <ABI.WinRT.Interop.IContextCallback.Vftbl> .Attach(ref contextCallbackPtr));

            contextCallback.ContextCallback(_ =>
            {
                base.Release();
                return(0);
            }, &data, IID_ICallbackWithNoReentrancyToApplicationSTA, 5);
        }
Ejemplo n.º 5
0
        public unsafe ObjectReference <T> As <T>(Guid iid)
        {
            ThrowIfDisposed();
            Marshal.ThrowExceptionForHR(VftblIUnknown.QueryInterface(ThisPtr, ref iid, out IntPtr thatPtr));
            if (IsAggregated)
            {
                Marshal.Release(thatPtr);
            }
            AddRefFromTrackerSource();

            var objRef = ObjectReference <T> .Attach(ref thatPtr);

            objRef.IsAggregated            = IsAggregated;
            objRef.PreventReleaseOnDispose = IsAggregated;
            objRef.ReferenceTrackerPtr     = ReferenceTrackerPtr;
            return(objRef);
        }
Ejemplo n.º 6
0
        public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId)
        {
            // TODO: "using var" with ref struct and remove the try/catch below
            var m = MarshalString.CreateMarshaler(runtimeClassId);

            try
            {
                IntPtr instancePtr;
                int    hr;
                (instancePtr, hr) = GetActivationFactory(MarshalString.GetAbi(m));
                return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr);
            }
            finally
            {
                m.Dispose();
            }
        }
Ejemplo n.º 7
0
        public static unsafe (ObjectReference <IActivationFactoryVftbl> obj, int hr) GetActivationFactory(string runtimeClassId)
        {
            // TODO: "using var" with ref struct and remove the try/catch below
            var         m       = MarshalString.CreateMarshaler(runtimeClassId);
            Func <bool> dispose = () => { m.Dispose(); return(false); };

            try
            {
                IntPtr instancePtr;
                int    hr;
                (instancePtr, hr) = GetActivationFactory(MarshalString.GetAbi(m));
                return(hr == 0 ? ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr) : null, hr);
            }
            catch (Exception) when(dispose())
            {
                // Will never execute
                return(default);
Ejemplo n.º 8
0
        public virtual unsafe int TryAs <T>(Guid iid, out ObjectReference <T> objRef)
        {
            objRef = null;
            ThrowIfDisposed();
            int hr = VftblIUnknown.QueryInterface(ThisPtr, ref iid, out IntPtr thatPtr);

            if (hr >= 0)
            {
                if (IsAggregated)
                {
                    Marshal.Release(thatPtr);
                }
                AddRefFromTrackerSource();

                objRef = ObjectReference <T> .Attach(ref thatPtr);

                objRef.IsAggregated            = IsAggregated;
                objRef.PreventReleaseOnDispose = IsAggregated;
                objRef.ReferenceTrackerPtr     = ReferenceTrackerPtr;
            }
            return(hr);
        }
Ejemplo n.º 9
0
 public unsafe ObjectReference <T> As <T>(Guid iid)
 {
     ThrowIfDisposed();
     Marshal.ThrowExceptionForHR(VftblIUnknown.QueryInterface(ThisPtr, ref iid, out IntPtr thatPtr));
     return(ObjectReference <T> .Attach(ref thatPtr));
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public static IObjectReference CreateCCWForObject(object obj)
        {
            IntPtr ccw = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport);

            return(ObjectReference <IUnknownVftbl> .Attach(ref ccw));
        }
Ejemplo n.º 12
0
 public static void DisposeContextCallback(IntPtr contextCallbackPtr)
 {
     using var contextcallback = ObjectReference <ABI.WinRT.Interop.IContextCallback.Vftbl> .Attach(ref contextCallbackPtr);
 }