-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListLocalWebCam.cs
77 lines (68 loc) · 2.86 KB
/
ListLocalWebCam.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
public class listlocalwebcam
{
internal static readonly Guid SystemDeviceEnum = new Guid(0x62BE5D10, 0x60EB, 0x11D0, 0xBD, 0x3B, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86);
internal static readonly Guid VideoInputDevice = new Guid(0x860BB310, 0x5D01, 0x11D0, 0xBD, 0x3B, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86);
[ComImport, Guid("55272A00-42CB-11CE-8135-00AA004BB851"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPropertyBag
{
[PreserveSig]
int Read(
[In, MarshalAs(UnmanagedType.LPWStr)] string propertyName,
[In, Out, MarshalAs(UnmanagedType.Struct)] ref object pVar,
[In] IntPtr pErrorLog);
[PreserveSig]
int Write(
[In, MarshalAs(UnmanagedType.LPWStr)] string propertyName,
[In, MarshalAs(UnmanagedType.Struct)] ref object pVar);
}
[ComImport,Guid("29840822-5B84-11D0-BD3B-00A0C911CE86"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ICreateDevEnum
{
[PreserveSig]
int CreateClassEnumerator([In] ref Guid type, [Out] out IEnumMoniker enumMoniker, [In] int flags);
}
public static void load(ComboBox lb)
{
Object bagObj = null;
object comObj = null;
ICreateDevEnum enumDev = null;
IEnumMoniker enumMon = null;
IMoniker[] moniker = new IMoniker[100];
IPropertyBag bag = null;
try
{
Type srvType = Type.GetTypeFromCLSID(SystemDeviceEnum);
comObj = Activator.CreateInstance(srvType);
enumDev = (ICreateDevEnum)comObj;
enumDev.CreateClassEnumerator(VideoInputDevice, out enumMon, 0);
Guid bagId = typeof(IPropertyBag).GUID;
while (enumMon.Next(1, moniker, IntPtr.Zero) == 0)
{
moniker[0].BindToStorage(null, null, ref bagId, out bagObj);
bag = (IPropertyBag)bagObj;
object val = "";
bag.Read("FriendlyName", ref val, IntPtr.Zero);
lb.Items.Add((string)val);
}
}
catch (Exception)
{
}
finally
{
bag = null;
if (bagObj != null)
{
Marshal.ReleaseComObject(bagObj);
bagObj = null;
}
enumDev = null;
enumMon = null;
moniker = null;
}
}
}