Esempio n. 1
0
        // Collect filters of specified category
		private void CollectFilters( Guid category )
		{
			object			comObj = null;
			ICreateDevEnum	enumDev;
			IEnumMoniker	enumMon = null;
			var		devMon = new IMoniker[1];

		    try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
                if ( srvType == null )
                    throw new ApplicationException( "Failed creating device enumerator" );

                // create device enumerator
                comObj = Activator.CreateInstance( srvType );
                enumDev = (ICreateDevEnum) comObj;

                // Create an enumerator to find filters of specified category
                int				hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
                if ( hr != 0 )
                    throw new ApplicationException( "No devices of the category" );

                // Collect all filters
                IntPtr n = IntPtr.Zero;
                while ( true )
                {
                    // Get next filter
                    hr = enumMon.Next( 1, devMon, n );
                    if ( ( hr != 0 ) || ( devMon[0] == null ) )
                        break;

                    // Add the filter
                    var filter = new FilterInfo( devMon[0] );
                    InnerList.Add( filter );

                    // Release COM object
                    Marshal.ReleaseComObject( devMon[0] );
                    devMon[0] = null;
                }

                // Sort the collection
                InnerList.Sort( );
            }
            catch
            {
            }
			finally
			{
				// release all COM objects
				enumDev = null;
				if ( comObj != null )
				{
					Marshal.ReleaseComObject( comObj );
					comObj = null;
				}
				if ( enumMon != null )
				{
					Marshal.ReleaseComObject( enumMon );
					enumMon = null;
				}
				if ( devMon[0] != null )
				{
					Marshal.ReleaseComObject( devMon[0] );
					devMon[0] = null;
				}
			}
		}
Esempio n. 2
0
        // Display property page for the specified object
        private void DisplayPropertyPage( IntPtr parentWindow, object sourceObject )
        {
            try
            {
                // retrieve ISpecifyPropertyPages interface of the device
                var pPropPages = sourceObject as ISpecifyPropertyPages;
                if (pPropPages==null)
                {
                     var e = sourceObject as IAMVfwCompressDialogs;
                    if (e == null)
                    {
                        throw new NotSupportedException("The video source does not support the compressor dialog page.");
                    }
                    e.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    return;
                }

                // get property pages from the property bag
                CAUUID caGUID;
                pPropPages.GetPages( out caGUID );

                // get filter info
                var filterInfo = new FilterInfo( _deviceMoniker );

                // create and display the OlePropertyFrame
                NativeMethods.OleCreatePropertyFrame(parentWindow, 0, 0, filterInfo.Name, 1, ref sourceObject, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);

                // release COM objects
                Marshal.FreeCoTaskMem( caGUID.pElems );
            }
            catch
            {
                // ignored
            }
        }
Esempio n. 3
0
        public static object CreateFilter( string filterMoniker )
        {
            object filterObject = null;
            object comObj = null;
            ICreateDevEnum enumDev;
            IEnumMoniker enumMon = null;
            var devMon = new IMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                if (srvType == null)
                    throw new ApplicationException("Failed creating device enumerator");

                // create device enumerator
                comObj = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                // Create an enumerator to find filters of specified category

                Guid cat = FilterCategory.VideoInputDevice;
                int hr = enumDev.CreateClassEnumerator(ref cat, out enumMon, 0);
                if (hr != 0)
                    throw new ApplicationException("No devices of the category");

                // Collect all filters
                IntPtr n = IntPtr.Zero;
                while (true)
                {
                    // Get next filter
                    hr = enumMon.Next(1, devMon, n);
                    if ((hr != 0) || (devMon[0] == null))
                        break;

                    // Add the filter
                    var filter = new FilterInfo(devMon[0]);
                    if (filter.MonikerString == filterMoniker)
                    {
                        Guid filterId = typeof(IBaseFilter).GUID;
                        devMon[0].BindToObject(null, null, ref filterId, out filterObject);
                        break;
                    }

                    // Release COM object
                    Marshal.ReleaseComObject(devMon[0]);
                    devMon[0] = null;
                }
            }
            catch
            {
            }
            finally
            {
                // release all COM objects
                enumDev = null;
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                    comObj = null;
                }
                if (enumMon != null)
                {
                    Marshal.ReleaseComObject(enumMon);
                    enumMon = null;
                }
                if (devMon[0] != null)
                {
                    Marshal.ReleaseComObject(devMon[0]);
                    devMon[0] = null;
                }
            }
            return filterObject;

            //// filter's object
            //object filterObject = null;
            //// bind context and moniker objects
            //IBindCtx bindCtx = null;
            //IMoniker moniker = null;

            //int n = 0;

            //// create bind context
            //if ( Win32.CreateBindCtx( 0, out bindCtx ) == 0 )
            //{
            //    // convert moniker`s string to a moniker
            //    if ( Win32.MkParseDisplayName( bindCtx, filterMoniker, ref n, out moniker ) == 0 )
            //    {
            //        // get device base filter
            //        Guid filterId = typeof( IBaseFilter ).GUID;
            //        moniker.BindToObject( null, null, ref filterId, out filterObject );

            //        Marshal.ReleaseComObject( moniker );
            //    }
            //    Marshal.ReleaseComObject( bindCtx );
            //}
            //return filterObject;
        }