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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds