private IBaseFilter FindCaptureDevice() { Debug.WriteLine("Start the Sub FindCaptureDevice"); int hr = 0; UCOMIEnumMoniker classEnum = null; UCOMIMoniker[] moniker = new UCOMIMoniker[1]; object source = null; ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum(); hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, CDef.None); Debug.WriteLine("Create an enumerator for the video capture devices : " + DsError.GetErrorText(hr)); DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(devEnum); if (classEnum == null) { throw new ApplicationException("No video capture device was detected.\\r\\n\\r\\n" + "This sample requires a video capture device, such as a USB WebCam,\\r\\n" + "to be installed and working properly. The sample will now close."); } int celt = 0; if (classEnum.Next(moniker.Length, moniker, out celt) == 0) { Guid iid = typeof(IBaseFilter).GUID; moniker[0].BindToObject(null, null, ref iid, out source); } else { throw new ApplicationException("Unable to access video capture device!"); } Marshal.ReleaseComObject(moniker[0]); Marshal.ReleaseComObject(classEnum); return((IBaseFilter)source); }
/// <summary> /// This method gets a UCOMIMoniker object. /// /// HACK: The only way to create a UCOMIMoniker from a moniker /// string is to use UCOMIMoniker.ParseDisplayName(). So I /// need ANY UCOMIMoniker object so that I can call /// ParseDisplayName(). Does anyone have a better solution? /// /// This assumes there is at least one video compressor filter /// installed on the system. /// </summary> protected UCOMIMoniker GetAnyMoniker() { Guid category = Uuid.FilterCategory.VideoCompressorCategory; int hr; object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { // Get the system device enumerator Type srvType = Type.GetTypeFromCLSID(Uuid.Clsid.SystemDeviceEnum); if (srvType == null) { throw new NotImplementedException("System Device Enumerator"); } comObj = Activator.CreateInstance(srvType); enumDev = (ICreateDevEnum)comObj; //Create an enumerator to find filters in category hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0); if (hr != 0) { throw new NotSupportedException("No devices of the category"); } // Get first filter int f; hr = enumMon.Next(1, mon, out f); if ((hr != 0)) { mon[0] = null; } return(mon[0]); } finally { enumDev = null; if (enumMon != null) { Marshal.ReleaseComObject(enumMon); } enumMon = null; if (comObj != null) { Marshal.ReleaseComObject(comObj); } comObj = null; } }
// Token: 0x06000341 RID: 833 RVA: 0x00013A08 File Offset: 0x00011C08 protected void getFilters(Guid category) { object obj = null; UCOMIEnumMoniker ucomienumMoniker = null; UCOMIMoniker[] array = new UCOMIMoniker[1]; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); obj = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID)); ICreateDevEnum createDevEnum = (ICreateDevEnum)obj; int num = createDevEnum.CreateClassEnumerator(ref category, out ucomienumMoniker, 0); if (num != 0) { } for (;;) { int num2; num = ucomienumMoniker.Next(1, array, out num2); if (num != 0) { break; } if (array[0] == null) { break; } Filter value = new Filter(array[0]); this.InnerList.Add(value); Marshal.ReleaseComObject(array[0]); array[0] = null; } this.InnerList.Sort(); } finally { if (array[0] != null) { Marshal.ReleaseComObject(array[0]); } array[0] = null; if (ucomienumMoniker != null) { Marshal.ReleaseComObject(ucomienumMoniker); } ucomienumMoniker = null; if (obj != null) { Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj)); } obj = null; } }
protected void getFilters(Guid category) { object o = null; ICreateDevEnum enum2 = null; UCOMIEnumMoniker ppEnumMoniker = null; UCOMIMoniker[] rgelt = new UCOMIMoniker[1]; try { int num; Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (typeFromCLSID == null) { throw new NotImplementedException("System Device Enumerator"); } o = Activator.CreateInstance(typeFromCLSID); enum2 = (ICreateDevEnum)o; if (enum2.CreateClassEnumerator(ref category, out ppEnumMoniker, 0) != 0) { throw new NotSupportedException("No devices of the category"); } while ((ppEnumMoniker.Next(1, rgelt, out num) == 0) && (rgelt[0] != null)) { Filter filter = new Filter(rgelt[0]); base.InnerList.Add(filter); Marshal.ReleaseComObject(rgelt[0]); rgelt[0] = null; } base.InnerList.Sort(); } finally { enum2 = null; if (rgelt[0] != null) { Marshal.ReleaseComObject(rgelt[0]); } rgelt[0] = null; if (ppEnumMoniker != null) { Marshal.ReleaseComObject(ppEnumMoniker); } ppEnumMoniker = null; if (o != null) { Marshal.ReleaseComObject(o); } o = null; } }
// This version of FindCaptureDevice is provide for education only. // A second version using the DsDevice helper class is define later. public IBaseFilter FindCaptureDevice() { int hr = 0; UCOMIEnumMoniker classEnum = null; UCOMIMoniker[] moniker = new UCOMIMoniker[1]; int fetched = 0; object source = null; // Create the system device enumerator ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum(); // Create an enumerator for the video capture devices hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0); DsError.ThrowExceptionForHR(hr); // The device enumerator is no more needed Marshal.ReleaseComObject(devEnum); // If there are no enumerators for the requested type, then // CreateClassEnumerator will succeed, but classEnum will be NULL. if (classEnum == null) { throw new ApplicationException("No video capture device was detected.\r\n\r\n" + "This sample requires a video capture device, such as a USB WebCam,\r\n" + "to be installed and working properly. The sample will now close."); } // Use the first video capture device on the device list. // Note that if the Next() call succeeds but there are no monikers, // it will return 1 (S_FALSE) (which is not a failure). Therefore, we // check that the return code is 0 (S_OK). if (classEnum.Next(moniker.Length, moniker, out fetched) == 0) { // Bind Moniker to a filter object Guid iid = typeof(IBaseFilter).GUID; moniker[0].BindToObject(null, null, ref iid, out source); } else { throw new ApplicationException("Unable to access video capture device!"); } // Release COM objects Marshal.ReleaseComObject(moniker[0]); Marshal.ReleaseComObject(classEnum); // An exception is thrown if cast fail return((IBaseFilter)source); }
/// <summary> /// Получает объект типа UCOMIMoniker. /// Требуется хотя бы один видеокомпрессор в системе /// </summary> protected UCOMIMoniker GetAnyMoniker() { Guid category = FilterCategory.VideoCompressorCategory; int hr; object comObj = null; ICreateDevEnum enumDev; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { //Получаем system device enumerator Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (srvType == null) { throw new NotImplementedException("System Device Enumerator"); } comObj = Activator.CreateInstance(srvType); enumDev = (ICreateDevEnum)comObj; //Создаем enumerator чтобы найти фильтры в категории hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0); if (hr != 0) { throw new NotSupportedException("No devices of the category"); } //Получаем первый фильтр hr = enumMon.Next(1, mon, out _); if ((hr != 0)) { mon[0] = null; } return(mon[0]); } finally { if (enumMon != null) { Marshal.ReleaseComObject(enumMon); } if (comObj != null) { Marshal.ReleaseComObject(comObj); } } }
protected UCOMIMoniker getAnyMoniker() { UCOMIMoniker moniker; Guid videoCompressorCategory = FilterCategory.VideoCompressorCategory; object o = null; ICreateDevEnum enum2 = null; UCOMIEnumMoniker ppEnumMoniker = null; UCOMIMoniker[] rgelt = new UCOMIMoniker[1]; try { int num; Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (typeFromCLSID == null) { throw new NotImplementedException("System Device Enumerator"); } o = Activator.CreateInstance(typeFromCLSID); enum2 = (ICreateDevEnum)o; if (enum2.CreateClassEnumerator(ref videoCompressorCategory, out ppEnumMoniker, 0) != 0) { throw new NotSupportedException("No devices of the category"); } if (ppEnumMoniker.Next(1, rgelt, out num) != 0) { rgelt[0] = null; } moniker = rgelt[0]; } finally { enum2 = null; if (ppEnumMoniker != null) { Marshal.ReleaseComObject(ppEnumMoniker); } ppEnumMoniker = null; if (o != null) { Marshal.ReleaseComObject(o); } o = null; } return(moniker); }
// Token: 0x0600033E RID: 830 RVA: 0x0001391C File Offset: 0x00011B1C protected UCOMIMoniker getAnyMoniker() { Guid videoCompressorCategory = FilterCategory.VideoCompressorCategory; object obj = null; UCOMIEnumMoniker ucomienumMoniker = null; UCOMIMoniker[] array = new UCOMIMoniker[1]; UCOMIMoniker result; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); obj = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID)); ICreateDevEnum createDevEnum = (ICreateDevEnum)obj; int num = createDevEnum.CreateClassEnumerator(ref videoCompressorCategory, out ucomienumMoniker, 0); int num2; num = ucomienumMoniker.Next(1, array, out num2); if (num != 0) { array[0] = null; } result = array[0]; } finally { if (ucomienumMoniker != null) { Marshal.ReleaseComObject(ucomienumMoniker); } ucomienumMoniker = null; if (obj != null) { Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj)); } obj = null; } return(result); }
public static bool GetDevicesOfCat(Guid cat, out ArrayList devs) { devs = null; int hr; object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (srvType == null) { throw new NotImplementedException("System Device Enumerator"); } comObj = Activator.CreateInstance(srvType); enumDev = (ICreateDevEnum)comObj; hr = enumDev.CreateClassEnumerator(ref cat, out enumMon, 0); if (hr != 0) { throw new NotSupportedException("No devices of the category"); } int f, count = 0; do { hr = enumMon.Next(1, mon, out f); if ((hr != 0) || (mon[0] == null)) { break; } DsDevice dev = new DsDevice(); dev.Name = GetFriendlyName(mon[0]); if (devs == null) { devs = new ArrayList(); } dev.Mon = mon[0]; mon[0] = null; devs.Add(dev); dev = null; count++; }while (true); return(count > 0); } catch (Exception) { if (devs != null) { foreach (DsDevice d in devs) { d.Dispose(); } devs = null; } return(false); } finally { enumDev = null; if (mon[0] != null) { Marshal.ReleaseComObject(mon[0]); } mon[0] = null; if (enumMon != null) { Marshal.ReleaseComObject(enumMon); } enumMon = null; if (comObj != null) { Marshal.ReleaseComObject(comObj); } comObj = null; } }
// Token: 0x0600027F RID: 639 RVA: 0x00012714 File Offset: 0x00010914 public static bool GetDevicesOfCat(Guid cat, ref ArrayList devs) { devs = null; object obj = null; UCOMIEnumMoniker ucomienumMoniker = null; UCOMIMoniker[] array = new UCOMIMoniker[1]; checked { bool result; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); obj = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID)); ICreateDevEnum createDevEnum = (ICreateDevEnum)obj; int num = createDevEnum.CreateClassEnumerator(ref cat, out ucomienumMoniker, 0); int num2 = 0; for (;;) { int num3; num = ucomienumMoniker.Next(1, array, out num3); if (num != 0) { break; } if (array[0] == null) { break; } DsDevice dsDevice = new DsDevice(); dsDevice.Name = DsDev.GetFriendlyName(array[0]); if (devs == null) { devs = new ArrayList(); } dsDevice.Mon = array[0]; array[0] = null; devs.Add(dsDevice); num2++; } result = (num2 > 0); } catch (Exception ex) { if (devs != null) { try { foreach (object obj2 in devs) { DsDevice dsDevice2 = (DsDevice)obj2; dsDevice2.Dispose(); } } finally { IEnumerator enumerator; if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } devs = null; } result = false; } finally { if (array[0] != null) { Marshal.ReleaseComObject(array[0]); } array[0] = null; if (ucomienumMoniker != null) { Marshal.ReleaseComObject(ucomienumMoniker); } ucomienumMoniker = null; if (obj != null) { Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj)); } obj = null; } return(result); } }
/// <summary> Populate the InnerList with a list of filters from a particular category </summary> protected void getFilters(Guid category) { int hr; object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { // Get the system device enumerator Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (srvType == null) { throw new NotImplementedException("System Device Enumerator"); } comObj = Activator.CreateInstance(srvType); enumDev = (ICreateDevEnum)comObj; // Create an enumerator to find filters in category hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0); if (hr != 0) { throw new NotSupportedException("No devices of the category"); } // Loop through the enumerator int f; do { // Next filter hr = enumMon.Next(1, mon, out f); if ((hr != 0) || (mon[0] == null)) { break; } // Add the filter Filter filter = new Filter(mon[0]); InnerList.Add(filter); lstVideoInput.Add(filter.Name); // Release resources Marshal.ReleaseComObject(mon[0]); mon[0] = null; }while (true); // Sort InnerList.Sort(); } finally { enumDev = null; if (mon[0] != null) { Marshal.ReleaseComObject(mon[0]); } mon[0] = null; if (enumMon != null) { Marshal.ReleaseComObject(enumMon); } enumMon = null; if (comObj != null) { Marshal.ReleaseComObject(comObj); } comObj = null; } }
// collect filters of specified category private void CollectFilters(Guid category) { object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] devMon = new UCOMIMoniker[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 int n; while (true) { // Get next filter hr = enumMon.Next(1, devMon, out n); if ((hr != 0) || (devMon[0] == null)) { break; } // Add the filter Filter filter = new Filter(devMon[0]); InnerList.Add(filter); // Release COM object Marshal.ReleaseComObject(devMon[0]); devMon[0] = null; } // Sort the collection InnerList.Sort(); } 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; } } }
public static bool GetDevicesOfCat(Guid cat, out ArrayList devs) { bool flag; devs = null; object o = null; ICreateDevEnum enum2 = null; UCOMIEnumMoniker ppEnumMoniker = null; UCOMIMoniker[] rgelt = new UCOMIMoniker[1]; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (typeFromCLSID == null) { throw new NotImplementedException("System Device Enumerator"); } o = Activator.CreateInstance(typeFromCLSID); enum2 = (ICreateDevEnum)o; if (enum2.CreateClassEnumerator(ref cat, out ppEnumMoniker, 0) != 0) { throw new NotSupportedException("No devices of the category"); } int num3 = 0; while (true) { int num2; if ((ppEnumMoniker.Next(1, rgelt, out num2) != 0) || (rgelt[0] == null)) { break; } DsDevice device = new DsDevice { Name = GetFriendlyName(rgelt[0]) }; if (devs == null) { devs = new ArrayList(); } device.Mon = rgelt[0]; rgelt[0] = null; devs.Add(device); device = null; num3++; } flag = num3 > 0; } catch (Exception) { if (devs != null) { foreach (DsDevice device2 in devs) { device2.Dispose(); } devs = null; } flag = false; } finally { enum2 = null; if (rgelt[0] != null) { Marshal.ReleaseComObject(rgelt[0]); } rgelt[0] = null; if (ppEnumMoniker != null) { Marshal.ReleaseComObject(ppEnumMoniker); } ppEnumMoniker = null; if (o != null) { Marshal.ReleaseComObject(o); } o = null; } return(flag); }