// Display property page for the specified object private void DisplayPropertyPage( IntPtr parentWindow, object sourceObject ) { try { // retrieve ISpecifyPropertyPages interface of the device ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages) sourceObject; // get property pages from the property bag CAUUID caGUID; pPropPages.GetPages( out caGUID ); // get filter info FilterInfo filterInfo = new FilterInfo( deviceMoniker ); // create and display the OlePropertyFrame Win32.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 { } }
// Collect filters of specified category private void CollectFilters( Guid category ) { object comObj = null; ICreateDevEnum enumDev = null; IEnumMoniker enumMon = null; IMoniker[] devMon = new IMoniker[1]; int hr; 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 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 FilterInfo 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; } } }