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

  • Rocket Mobile® for IBM i is an enterprise mobile application development and deployment platform for customers who rely on the IBM i system. Rocket Mobile for IBM i enables customers to leave proven applications in-place and rapidly repurpose them into new managed and secure mobile applications. Fast, easy creation of mobile, web, and hybrid mobile applications that deploy to any iOS, Android, or Windows mobile phone or tablet Built-in integration for seamless repurposing of existing IBM i applications …

  • Complex hybrid environments can make it difficult to track interdependencies, increasing the risk of disrupting critical business services. In this white paper by EMA, you'll learn how application discovery and dependency mapping can help you: Meet granular targets for availability, cost, and time-to-revenue for cloud services. Accelerate mean time to repair (MTTR) while communicating better with stakeholders. Manage even the most complex hybrid environments more efficiently and effectively Understand the …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date