/// <summary> /// Queries a managed object for a particular COM interface support. /// </summary> ///<typeparam name="T">The type of the COM interface to query</typeparam> /// <param name="comObject">The managed COM object.</param> ///<returns>An instance of the queried interface</returns> /// <msdn-id>ms682521</msdn-id> /// <unmanaged>IUnknown::QueryInterface</unmanaged> /// <unmanaged-short>IUnknown::QueryInterface</unmanaged-short> public static T QueryInterface <T>(object comObject) where T : ComObject { using (var tempObject = new ComObject(Marshal.GetIUnknownForObject(comObject))) { return(tempObject.QueryInterface <T>()); } }
private void InitRenderTarget(IntPtr surface) { IntPtr sharedHandle; var c = new SharpDX.ComObject(surface); var D3DImageResource = c.QueryInterface <SharpDX.DXGI.Resource>(); sharedHandle = D3DImageResource.SharedHandle; var tempResource = D3DDevice.OpenSharedResource <SharpDX.Direct3D11.Resource>(sharedHandle); var d3DImageTexture = tempResource.QueryInterface <Texture2D>(); RenderTarget = new RenderTargetView(D3DDevice, d3DImageTexture); var vp = new ViewportF { Width = (float)host.ActualWidth, Height = (float)host.ActualHeight, MinDepth = 0.0f, MaxDepth = 1.0f }; D3DContext.Rasterizer.SetViewport(vp); D3DContext.OutputMerger.SetRenderTargets(RenderTarget); ////Cleanup tempResource.Dispose(); d3DImageTexture.Dispose(); }
/// <summary> /// Queries a managed object for a particular COM interface support (This method is a shortcut to <see cref="QueryInterface"/>) /// </summary> ///<typeparam name="T">The type of the COM interface to query</typeparam> /// <param name="iunknownPtr">The managed COM object.</param> ///<returns>An instance of the queried interface</returns> /// <msdn-id>ms682521</msdn-id> /// <unmanaged>IUnknown::QueryInterface</unmanaged> /// <unmanaged-short>IUnknown::QueryInterface</unmanaged-short> public static T As <T>(IntPtr iunknownPtr) where T : ComObject { using (var tempObject = new ComObject(iunknownPtr)) { return(tempObject.QueryInterface <T>()); } }
/// <summary> /// Opens the given video file and plays it directly. /// </summary> /// <param name="videoLink">The link to the video file.</param> public async Task OpenAndShowVideoFileAsync(ResourceLink videoLink) { // Check for correct state if (this.State != MediaPlayerState.NothingToDo) { throw new InvalidOperationException("Unable to open video file as long as there is another video playing!"); } // Apply new state this.State = MediaPlayerState.Opening; try { // Create media session and a corresponding event listener obect for async events MF.MediaFactory.CreateMediaSession(null, out m_mediaSession); m_sessionEventHandler = MFSessionEventListener.AttachTo(m_mediaSession); m_sessionEventHandler.EndOfPresentation += OnSessionEventHandlerEndOfPresentationReached; // Create source object MF.SourceResolver sourceResolver = new MF.SourceResolver(); MF.ObjectType objType = MF.ObjectType.Invalid; m_videoSourceStreamNet = videoLink.OpenInputStream(); m_videoSourceStream = new MF.ByteStream(m_videoSourceStreamNet); SharpDX.ComObject objSource = sourceResolver.CreateObjectFromStream( m_videoSourceStream, "Dummy." + videoLink.FileExtension, MF.SourceResolverFlags.MediaSource, out objType); using (MF.MediaSource mediaSource = objSource.QueryInterface <MF.MediaSource>()) { GraphicsHelper.SafeDispose(ref objSource); GraphicsHelper.SafeDispose(ref sourceResolver); await ShowVideoAsync(mediaSource); } // Video opened successfully m_currentVideoLink = videoLink; m_currentCaptureDevice = null; this.State = MediaPlayerState.Playing; } catch (Exception) { // Unload all resources in case of an exception DisposeResources(); throw; } }
public void InitRenderTargetSurface(IntPtr Resource) { ZBuffer?.Dispose(); DepthStencilViewRef?.Dispose(); RenderTargetViewRef?.Dispose(); RenderTarget2D?.Dispose(); SharpDX.DXGI.Resource dxgiResource; using (var r = new SharpDX.ComObject(Resource)) { dxgiResource = r.QueryInterface <SharpDX.DXGI.Resource>(); } Texture2D OutputResource = DeviceRef.OpenSharedResource <Texture2D>(dxgiResource.SharedHandle); using (var surface = DeviceRef.OpenSharedResource <Surface>(dxgiResource.SharedHandle)) { RenderTarget2D = new RenderTarget(Factory2D, surface, RenderTarget2DProperites); } //Crash everything //dxgiResource.Dispose(); RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype; RenderTargetViewRef = new RenderTargetView(DeviceRef, OutputResource); Texture2DDescription OutputDesc = OutputResource.Description; if (OutputDesc.Width != Width || OutputDesc.Height != Height) { Width = OutputDesc.Width; Height = OutputDesc.Height; SetUpViewport(); } ZBufferTextureDescription.Width = Width; ZBufferTextureDescription.Height = Height; ZBuffer = new Texture2D(DeviceRef, ZBufferTextureDescription); DepthStencilViewRef = new DepthStencilView(DeviceRef, ZBuffer, new DepthStencilViewDescription { Format = Format.D32_Float, Dimension = DepthStencilViewDimension.Texture2D, Flags = DepthStencilViewFlags.None, }); Context.OutputMerger.SetRenderTargets(DepthStencilViewRef, RenderTargetViewRef); OnInitRenderTarget?.Invoke(); OutputResource?.Dispose(); }
private void CreateSwapChain(ref SwapChainDescription1 swapChainDescription1, Factory4 factory) { using (var sc1 = new SwapChain1(factory, commandQueue, ref swapChainDescription1)) { swapChain = Collect(sc1.QueryInterface<SwapChain3>()); using (var comPtr = new ComObject(panel)) { using (var native = comPtr.QueryInterface<ISwapChainPanelNative>()) { native.SwapChain = swapChain; } } } }
public static T QueryInterface <T>(object comObject) where T : ComObject { using (ComObject comObject1 = new ComObject(Marshal.GetIUnknownForObject(comObject))) return(comObject1.QueryInterface <T>()); }
public static T As <T>(IntPtr iunknownPtr) where T : ComObject { using (ComObject comObject = new ComObject(iunknownPtr)) return(comObject.QueryInterface <T>()); }