public static T CastWinRTObject <T>(object value)
        {
#if NET5_0_OR_GREATER
            return(MarshalInterface <T> .FromAbi(Marshal.GetIUnknownForObject(value)));
#else
            return((T)value);
#endif
        }
Example #2
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);
        }
Example #3
0
        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);
        }
Example #4
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
        }
Example #5
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);
            }
        }
Example #6
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));
        }
Example #7
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));
        }
Example #8
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));
        }
Example #9
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 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);
        }
        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);
        }