예제 #1
0
        private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name, IntPtr *result)
        {
            global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default;
            try
            {
                string       _name        = MarshalString.FromAbi(name);
                object       target       = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr);
                PropertyInfo propertyInfo = target.GetType().GetProperty(
                    _name,
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);

                if (propertyInfo is object)
                {
                    __result = new ManagedCustomProperty(propertyInfo);
                }

                *result = MarshalInterface <global::Microsoft.UI.Xaml.Data.ICustomProperty> .FromManaged(__result);
            }
            catch (Exception __exception__)
            {
                global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
                return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__));
            }
            return(0);
        }
예제 #2
0
        private static unsafe int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr name, global::ABI.System.Type type, IntPtr *result)
        {
            global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default;
            try
            {
                string       _name        = MarshalString.FromAbi(name);
                object       target       = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr);
                PropertyInfo propertyInfo = target.GetType().GetProperty(
                    _name,
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
                    null,                                                                   // default binder
                    null,                                                                   // ignore return type
                    new Type[] { global::ABI.System.Type.FromAbi(type) },                   // indexed parameter type
                    null                                                                    // ignore type modifier
                    );

                if (propertyInfo is object)
                {
                    __result = new ManagedCustomProperty(propertyInfo);
                }

                *result = MarshalInterface <global::Microsoft.UI.Xaml.Data.ICustomProperty> .FromManaged(__result);
            }
            catch (Exception __exception__)
            {
                global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
                return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__));
            }
            return(0);
        }
예제 #3
0
        public unsafe IObjectReference CreateInstanceWithAllParameters(global::System.Collections.Specialized.NotifyCollectionChangedAction action, global::System.Collections.IList newItems, global::System.Collections.IList oldItems, int newIndex, int oldIndex, object baseInterface, out IObjectReference innerInterface)
        {
            IObjectReference __newItems       = default;
            IObjectReference __oldItems       = default;
            IObjectReference __baseInterface  = default;
            IntPtr           __innerInterface = default;
            IntPtr           __retval         = default;

            try
            {
                __newItems = MarshalInterface <global::System.Collections.IList> .CreateMarshaler(newItems);

                __oldItems = MarshalInterface <global::System.Collections.IList> .CreateMarshaler(oldItems);

                __baseInterface = MarshalInspectable <object> .CreateMarshaler(baseInterface);

                global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstanceWithAllParameters_0(ThisPtr, action, MarshalInterface <global::System.Collections.IList> .GetAbi(__newItems), MarshalInterface <global::System.Collections.IList> .GetAbi(__oldItems), newIndex, oldIndex, MarshalInspectable <object> .GetAbi(__baseInterface), out __innerInterface, out __retval));
                innerInterface = ObjectReference <IUnknownVftbl> .FromAbi(__innerInterface);

                return(ObjectReference <IUnknownVftbl> .FromAbi(__retval));
            }
            finally
            {
                MarshalInterface <global::System.Collections.IList> .DisposeMarshaler(__newItems);

                MarshalInterface <global::System.Collections.IList> .DisposeMarshaler(__oldItems);

                MarshalInspectable <object> .DisposeMarshaler(__baseInterface);

                MarshalInspectable <object> .DisposeAbi(__innerInterface);

                MarshalInspectable <object> .DisposeAbi(__retval);
            }
        }
예제 #4
0
        private static void ValidatePInvokes(bool validateUseRegistered)
        {
            string scenario = validateUseRegistered ? "use registered wrapper" : "fall back to runtime";

            Console.WriteLine($"Running {nameof(ValidatePInvokes)}: {scenario}...");

            GlobalComWrappers.Instance.ReturnInvalid = !validateUseRegistered;

            Console.WriteLine($" -- Validate MarshalAs IUnknown...");
            ValidateInterfaceMarshaler <object>(MarshalInterface.UpdateTestObjectAsIUnknown, shouldSucceed: validateUseRegistered);
            object obj = MarshalInterface.CreateTrackerObjectAsIUnknown();

            Assert.AreEqual(validateUseRegistered, obj is FakeWrapper, $"Should{(validateUseRegistered ? string.Empty : "not")} have returned {nameof(FakeWrapper)} instance");

            if (validateUseRegistered)
            {
                Console.WriteLine($" -- Validate MarshalAs IDispatch...");
                ValidateInterfaceMarshaler <object>(MarshalInterface.UpdateTestObjectAsIDispatch, shouldSucceed: true, new TestEx(IID_IDISPATCH));
            }

            Console.WriteLine($" -- Validate MarshalAs Interface...");
            ValidateInterfaceMarshaler <ITest>(MarshalInterface.UpdateTestObjectAsInterface, shouldSucceed: true);

            if (validateUseRegistered)
            {
                Assert.Throws <InvalidCastException>(() => MarshalInterface.CreateTrackerObjectWrongType());

                FakeWrapper wrapper = MarshalInterface.CreateTrackerObjectAsInterface();
                Assert.IsNotNull(wrapper, $"Should have returned {nameof(FakeWrapper)} instance");
            }
        }
예제 #5
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);
            }
        }
        public static T CastWinRTObject <T>(object value)
        {
#if NET5_0_OR_GREATER
            return(MarshalInterface <T> .FromAbi(Marshal.GetIUnknownForObject(value)));
#else
            return((T)value);
#endif
        }
예제 #7
0
        public static ICompositionSurface CreateCompositionSurfaceForSwapChain(this Compositor compositor, SharpDX.DXGI.SwapChain1 swapChain)
        {
            var interop = compositor.As <ICompositorInterop>();

            interop.CreateCompositionSurfaceForSwapChain(swapChain.NativePointer, out var raw);
            var result = MarshalInterface <ICompositionSurface> .FromAbi(raw);

            Marshal.Release(raw);
            return(result);
        }
예제 #8
0
        private static T Create <T>(Type type)
        {
            object instance = Activator.CreateInstance(type);

#if NET
            IntPtr pointer = Marshal.GetIUnknownForObject(instance);
            return(MarshalInterface <T> .FromAbi(pointer));
#else
            return((T)instance);
#endif
        }
예제 #9
0
파일: Share.uwp.cs 프로젝트: sung-su/maui
        public static DataTransferManager GetDataTransferManager(IntPtr appWindow)
        {
            var    interop = DataTransferManager.As <IDataTransferManagerInterop>();
            Guid   id      = new Guid(0xa5caee9b, 0x8708, 0x49d1, 0x8d, 0x36, 0x67, 0xd2, 0x5a, 0x8d, 0xa0, 0x0c);
            IntPtr result;

            result = interop.GetForWindow(appWindow, id);
            DataTransferManager dataTransferManager = MarshalInterface <DataTransferManager> .FromAbi(result);

            return(dataTransferManager);
        }
예제 #10
0
        public global::WinRT.Interop.IWeakReference GetWeakReference()
        {
            IntPtr objRef = IntPtr.Zero;

            try
            {
                ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.GetWeakReference(ThisPtr, out objRef));
                return(MarshalInterface <WinRT.Interop.IWeakReference> .FromAbi(objRef));
            }
            finally
            {
                MarshalInspectable.DisposeAbi(objRef);
            }
        }
 private static unsafe int Do_Abi_First_0(IntPtr thisPtr, out IntPtr __return_value__)
 {
     __return_value__ = default;
     try
     {
         var __this = global::WinRT.ComWrappersSupport.FindObject <global::System.Collections.Generic.IEnumerable <T> >(thisPtr);
         __return_value__ = MarshalInterface <global::System.Collections.Generic.IEnumerator <T> > .FromManaged(__this.GetEnumerator());
     }
     catch (Exception __exception__)
     {
         global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
         return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__));
     }
     return(0);
 }
예제 #12
0
        public static AccountsSettingsPane GetForWindow(IntPtr hWnd)
        {
            IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
                AccountsSettingsPane.As <IAccountsSettingsPaneInterop>();
            //Guid guid = typeof(AccountsSettingsPane).GUID;
            Guid guid = //WinRT.GuidGenerator.CreateIID(typeof(IAccountsSettingPane));
                        Guid.Parse("81EA942C-4F09-4406-A538-838D9B14B7E6");

            //IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
            //    (IAccountsSettingsPaneInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(AccountsSettingsPane));
            //Guid guid = typeof(AccountsSettingsPane).GetInterface("IAccountsSettingsPane").GUID;

            accountsSettingsPaneInterop.GetForWindow(hWnd, ref guid, out IntPtr result);
            return(MarshalInterface <AccountsSettingsPane> .FromAbi(result));
        }
예제 #13
0
        public static IAsyncOperation <WebTokenRequestResult> RequestTokenForWindowAsync(IntPtr hWnd, WebTokenRequest request)
        {
            IWebAuthenticationCoreManagerInterop webAuthenticationCoreManagerInterop =
                WebAuthenticationCoreManager.As <IWebAuthenticationCoreManagerInterop>();
            Guid guid = WinRT.GuidGenerator.CreateIID(typeof(IAsyncOperation <WebTokenRequestResult>));

            var requestPtr = MarshalInspectable <WebTokenRequest> .FromManaged(request);

            webAuthenticationCoreManagerInterop.RequestTokenForWindowAsync(
                hWnd,
                requestPtr,
                ref guid,
                out IntPtr result);

            return(MarshalInterface <IAsyncOperation <WebTokenRequestResult> > .FromAbi(result));
        }
예제 #14
0
            private static unsafe int Do_Abi_GetView_2(IntPtr thisPtr, out IntPtr __return_value__)
            {
                global::System.Collections.Generic.IReadOnlyList <T> ____return_value__ = default;
                __return_value__ = default;

                try
                {
                    ____return_value__ = FindAdapter(thisPtr).GetView();
                    __return_value__   = MarshalInterface <global::System.Collections.Generic.IReadOnlyList <T> > .FromManaged(____return_value__);
                }
                catch (Exception __exception__)
                {
                    global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__);
                    return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__));
                }
                return(0);
            }
예제 #15
0
            private static int Do_Abi_Get_Source(IntPtr thisPtr, uint index, out IntPtr value)
            {
                value = default;

                try
                {
                    var source = ComWrappersSupport.FindObject <global::Windows.Graphics.Effects.Interop.IGraphicsEffectD2D1Interop>(thisPtr).GetSource(index);

                    value = MarshalInterface <global::Windows.Graphics.Effects.IGraphicsEffectSource> .FromManaged(source);
                }
                catch (Exception ex)
                {
                    return(Marshal.GetHRForException(ex));
                }

                return(0);
            }
예제 #16
0
        public static IAsyncAction ShowAddAccountForWindowAsync(IntPtr hWnd)
        {
            IWebAuthenticationCoreManagerInterop webAuthenticationCoreManagerInterop =
                WebAuthenticationCoreManager.As <IWebAuthenticationCoreManagerInterop>();

            IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
                AccountsSettingsPane.As <IAccountsSettingsPaneInterop>();
            //Guid guid = typeof(IAsyncAction).GUID;
            Guid guid = WinRT.GuidGenerator.CreateIID(typeof(IAsyncAction));

            //IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
            //    (IAccountsSettingsPaneInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(AccountsSettingsPane));
            //Guid guid = typeof(IAsyncAction).GUID;

            accountsSettingsPaneInterop.ShowAddAccountForWindowAsync(hWnd, ref guid, out IntPtr result);

            return(MarshalInterface <IAsyncAction> .FromAbi(result));
        }
예제 #17
0
        public static IDirect3DDevice CreateDevice()
        {
            using var d3dDevice = new SharpDX.Direct3D11.Device(
                      driverType: SharpDX.Direct3D.DriverType.Hardware,
                      flags: SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);

            // Acquire the DXGI interface for the Direct3D device.
            using var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device3>();

            // Wrap the native device using a WinRT interop object.
            var hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr abi);

            if (hr != 0)
            {
                throw new InvalidProgramException($"CreateDirect3D11DeviceFromDXGIDevice failed with error code {hr}.");
            }

            return(MarshalInterface <IDirect3DDevice> .FromAbi(abi));
        }
        public static IDirect3DDevice CreateDirect3DDeviceFromSharpDXDevice(SharpDX.Direct3D11.Device d3dDevice)
        {
            IDirect3DDevice device = null;

            // Acquire the DXGI interface for the Direct3D device.
            using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Wrap the native device using a WinRT interop object.
                uint hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr pUnknown);

                if (hr == 0)
                {
                    device = MarshalInterface <IDirect3DDevice> .FromAbi(pUnknown);

                    Marshal.Release(pUnknown);
                }
            }

            return(device);
        }
        public static IDirect3DSurface CreateDirect3DSurfaceFromSharpDXTexture(SharpDX.Direct3D11.Texture2D texture)
        {
            IDirect3DSurface surface = null;

            // Acquire the DXGI interface for the Direct3D surface.
            using (var dxgiSurface = texture.QueryInterface <SharpDX.DXGI.Surface>())
            {
                // Wrap the native device using a WinRT interop object.
                uint hr = CreateDirect3D11SurfaceFromDXGISurface(dxgiSurface.NativePointer, out IntPtr pUnknown);

                if (hr == 0)
                {
                    surface = MarshalInterface <IDirect3DSurface> .FromAbi(pUnknown);

                    Marshal.Release(pUnknown);
                }
            }

            return(surface);
        }
예제 #20
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);
            }
        }
예제 #21
0
 public static IObjectReference CreateMarshaler(global::System.Collections.Generic.KeyValuePair <K, V> obj) =>
 MarshalInterface <global::System.Collections.Generic.KeyValuePair <K, V> > .CreateMarshaler(obj);