Click here to Skip to main content
12,894,708 members (50,754 online)
Click here to Skip to main content

Stats

176K views
7.9K downloads
136 bookmarked
Posted 17 Sep 2007

Webcamera, Multithreading and VFW

, 15 Feb 2008 CPOL
An article on webcamera frame-grabbing in a multi-thread environment
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace SevenZ.WebCamera
{
   public class Device
   {
      public string Name;
      public string Version;

      public Device(string name, string version)
      {
         this.Name = name; this.Version = version;
      }

      public override string ToString()
      {
         return Name + "  " + Version;
      }
      
   }

   public class WebCameraDeviceManager
   {
      [DllImport("avicap32.dll")]
      static extern bool capGetDriverDescription(int wDriverIndex,
          [MarshalAs(UnmanagedType.VBByRefStr)]ref String lpszName,
          int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref String lpszVer, int cbVer);
      
      List<Device> devices = new List<Device>(10);

      public WebCameraDeviceManager()
      {
         Refresh();
      }

      public void Refresh()
      {
         string name = "".PadRight(100), version = "".PadRight(100);

         for (int i = 0; i < 10; i++)
         {
            if (capGetDriverDescription(i, ref name, 100, ref version, 100))
            {
               Device d = new Device(name,version);
               d.Name = name.Trim();
               d.Version = version.Trim();
               devices.Add(d);
            }
         }
      }

      public Device Device(int index)
      {
         return devices[index];
      }

      public Device[] Devices
      {
         get { return devices.ToArray(); }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Zaur Nasibov
Software Developer
Finland Finland
I'm a Master degree student, studying at the University of Joensuu, Finland.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 16 Feb 2008
Article Copyright 2007 by Zaur Nasibov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid