Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello.
I use following code to get list of webcam devices but return Name not equal to device name.
I want to connect to webcam device using index of device.
help me.thanks.

C#
      ArrayList ListOfDevices = new ArrayList();
      string Name = String.Empty.PadRight(50);
      string Version = String.Empty.PadRight(100);
      bool EndOfDeviceList = false;
      short index = 0;
      int DeviceID = 0;
     [DllImport("avicap32.dll")]
      protected static extern bool capGetDriverDescriptionA(short wDriverIndex,
          [MarshalAs(UnmanagedType.VBByRefStr)]ref String lpszName,
           int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref String lpszVer, int cbVer);


do
          {
              // Get Driver name and version
              EndOfDeviceList = capGetDriverDescriptionA(index, ref Name, 100, ref Version, 100);
              // If there was a device add device name to the list
              if (EndOfDeviceList)
                  ListOfDevices.Add(Name.Trim());
                  //c1.Items.Add(Name.Trim());
              index += 1;
          }
          while (!(EndOfDeviceList == false));

          foreach (string NameCamera in ListOfDevices)
          {
              int i = 0;
              if (NameCamera == "device name")
                  DeviceID = i;
              i++;
          }
          SendMessage(mCapHwnd, WM_CAP_CONNECT, DeviceID, 0);
          SendMessage(mCapHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);   //66
          SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 1, 0);
Posted
Updated 10-Sep-11 19:45pm
v5

1 solution

You might need to do some COM programming for this.
This can be a good reference for you :

See this
 
Share this answer
 
v2
Comments
dimas1971 8-Feb-13 8:30am    
It is not a solution at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900