Video For Windows Wrapper Class (CVFWImageProcessor)

Performs DIB video capture to memory with or without preview mode.


Environment: VC6, NT, W2K, Win98, Win95.

One of the main reasons why I wrote this class was to simplify the process of capturing images from a Video For Windows camera device. The Platform SDK Video for Windows (VFW) API did not seem to adequately document the VFW functions in the way that I wanted to implement them. My goal was to capture images from a capture device into a memory DIB. The VFW functions only seemed to be geared around saving captured images directly to disk. I wanted to be able to run image diagnostics on the captured contents without having to reload it from disk after the capture (very inneficient). I also did not want to deal with preview mode and trying to capture from that interface.

Microsoft did not appear to have built an MFC class around the VFW APIs. Instead, they chose to only utilize COM under the Windows Media Technologies to interface to VFW. So, I thought that I would try to develop a simplified class to the VFW APIs. The result is the CVFWImageProcessor class.

VFW APIs utilize a window handle as the point of reference for most of its functions which I encapsulated in the class. Most VFW API calls are dispatched under the windows message queue. In order to capture the DIB to memory instead of to disk, I decided to create a seperate thread that would be used to dispatch VFW message. This would allow me to syncronize the VFW callback functions without relying on the main message queue of my windows appliation.

Most of the work in the CVFWImageProcessor class focusses around the simplification of memory DIB capture. I added some additional member functions as wrappers around already existing VFW APIs. I did not incorporate all VFW APIs, just the ones that I thought were important for my application. I am sure that others may want to add or modify these members.

All of the testing that I performed was with Webcams that had no on-board compression. I am not sure how devices with built-in compression would function under this implementation.

Note that preview mode does not have to be active in order to capture a DIB to memory.

The download package includes a sample windows dialog application that shows how to use some of the features of the class.

I am well aware that there are probably ways that this class can be improved. My main goal was to illustrate a method for doing memory DIB captures with an easy to use class interface.

// Sample source on implemented CVFWImageProcessor class 
// to capture a single DIB frame to memory.

CVFWImageProcessor VFWProc;
ULONG BitmapSize;

VFWProc.Initialize(); // Intialize first found VFW device.

pBitmap = NULL; // CaptureDIB will automatically 
                // allocate this if it is set to NULL.

// Capture an image from the capture device.
if (VFWProc.CaptureDIB(&pBitmap, 0, &BitmapSize))
  // pBitmap captured successfully. Do whatever with it.

  delete pBitmap;    // Delete it when done.

VFWProc.Destroy();   // Done using VFW object.

UPDATES - August 29, 2001

The following changes were made:

  1. Removed DebugRelease configuration. This had a reference to GEAR32PD.LIB which is not used by the project.
  2. Removed all commented out sections concerning JPEG capture. JPEG capture is only available when I used the ImageGear package from AccuSoft which I could not redistribute. It was commented out, but was causing some confusion. So I removed it altogether.
  3. Corrected a lockup problem when using functions CVFWImageProcessor::DlgVideoDisplay(), CVFWImageProcessor::DlgVideoFormat(), and CVFWImageProcessor::DlgVideoSource().


Download demo project - 19 Kb

About the Author

Ken Varn

Currently developing Digital Video Recorder software for security surveilance under Windows using Visual C++ C#, and Microsoft .NET Framework.


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • Live Event Date: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds