DsBugWO.cs
Upload User: wuming6209
Upload Date: 2013-06-06
Package Size: 161k
Code Size: 1k
Category:

Video Capture

Development Platform:

Visual C++

  1. /******************************************************
  2.                   DirectShow .NET
  3.       netmaster@swissonline.ch
  4. *******************************************************/
  5. //           WORKAROUND FOR DS BUGs
  6. using System;
  7. using System.Text;
  8. using System.Runtime.InteropServices;
  9. namespace DShowNET
  10. {
  11. public class DsBugWO
  12. {
  13. /*
  14. works:
  15. CoCreateInstance( CLSID_CaptureGraphBuilder2, ..., IID_ICaptureGraphBuilder2, ...);
  16. doesn't (E_NOTIMPL):
  17. CoCreateInstance( CLSID_CaptureGraphBuilder2, ..., IID_IUnknown, ...);
  18. thus .NET 'Activator.CreateInstance' fails
  19. */
  20. public static object CreateDsInstance( ref Guid clsid, ref Guid riid )
  21. {
  22. IntPtr ptrIf;
  23. int hr = CoCreateInstance( ref clsid, IntPtr.Zero, CLSCTX.Inproc, ref riid, out ptrIf );
  24. if( (hr != 0) || (ptrIf == IntPtr.Zero) )
  25. Marshal.ThrowExceptionForHR( hr );
  26. Guid iu = new Guid( "00000000-0000-0000-C000-000000000046" );
  27. IntPtr ptrXX;
  28. hr = Marshal.QueryInterface( ptrIf, ref iu, out ptrXX );
  29. object ooo = System.Runtime.Remoting.Services.EnterpriseServicesHelper.WrapIUnknownWithComObject( ptrIf );
  30. int ct = Marshal.Release( ptrIf );
  31. return ooo;
  32. }
  33. [DllImport("ole32.dll") ]
  34. private static extern int CoCreateInstance( ref Guid clsid, IntPtr pUnkOuter, CLSCTX dwClsContext, ref Guid iid, out IntPtr ptrIf );
  35. }
  36. [Flags]
  37. internal enum CLSCTX
  38. {
  39. Inproc = 0x03,
  40. Server = 0x15,
  41. All = 0x17,
  42. }
  43. } // namespace DShowNET