public DxgiSwapChain2 CreateSwapChainForWindowHandle(
            object device,
            IntPtr hwnd,
            DxgiSwapChainDesc1 desc,
            DxgiSwapChainFullscreenDesc?fullscreenDesc,
            DxgiOutput2 restrictToOutput)
        {
            if (fullscreenDesc == null)
            {
                return(new DxgiSwapChain2(this.factory.CreateSwapChainForWindowHandle(
                                              device,
                                              hwnd,
                                              ref desc,
                                              IntPtr.Zero,
                                              restrictToOutput == null ? null : restrictToOutput.GetHandle <IDxgiOutput>())));
            }
            else
            {
                IntPtr fullscreenDescPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DxgiSwapChainFullscreenDesc)));

                try
                {
                    Marshal.StructureToPtr(fullscreenDesc.Value, fullscreenDescPtr, false);
                    return(new DxgiSwapChain2(this.factory.CreateSwapChainForWindowHandle(
                                                  device,
                                                  hwnd,
                                                  ref desc,
                                                  fullscreenDescPtr,
                                                  restrictToOutput == null ? null : restrictToOutput.GetHandle <IDxgiOutput>())));
                }
                finally
                {
                    Marshal.FreeHGlobal(fullscreenDescPtr);
                }
            }
        }
        public DxgiSwapChain2 CreateSwapChainForWindowHandle(
            object device,
            IntPtr hwnd,
            DxgiSwapChainDesc1 desc,
            DxgiSwapChainFullscreenDesc? fullscreenDesc,
            DxgiOutput2 restrictToOutput)
        {
            if (fullscreenDesc == null)
            {
                return new DxgiSwapChain2(this.factory.CreateSwapChainForWindowHandle(
                    device,
                    hwnd,
                    ref desc,
                    IntPtr.Zero,
                    restrictToOutput == null ? null : restrictToOutput.GetHandle<IDxgiOutput>()));
            }
            else
            {
                IntPtr fullscreenDescPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DxgiSwapChainFullscreenDesc)));

                try
                {
                    Marshal.StructureToPtr(fullscreenDesc.Value, fullscreenDescPtr, false);
                    return new DxgiSwapChain2(this.factory.CreateSwapChainForWindowHandle(
                        device,
                        hwnd,
                        ref desc,
                        fullscreenDescPtr,
                        restrictToOutput == null ? null : restrictToOutput.GetHandle<IDxgiOutput>()));
                }
                finally
                {
                    Marshal.FreeHGlobal(fullscreenDescPtr);
                }
            }
        }