Video for Windows Single-Frame Capture Class Without MFC

This is a thoroughly trimmed-down version of Ken Varn's Video For Windows wrapper class (CVFWImageProcessor). I was creating a Macromedia Director Xtra that gets a live image and processes it. I needed to grab the image without using MFC because, to the best of my knowledge, MFC and MOA (Macromedia Open Architecture) are not compatible. Briefly, here's what I did in case someone wants to do it themselves.

  1. I replaced all MFC data types with ordinary C/C++ or Win32 data types where I could.
  2. I got rid of multithreading altogether because converting MFC threads to Win32 threads looked like it was going to be a major headache.
  3. I removed the MFC #includes.
  4. Finally, I took out everything else I didn't need, such as the functions for dialogs and for streaming to a file.

    Oh, and it doesn't seem right to call the class CVFWImageProcessor any more since it doesn't do much processing, so I call it CVFWCapture.

The demo project includes VFWCaptureTest.cpp, which shows you how to use the CVFWCapture class. You call the CaptureDIB method exactly as shown in Ken's article.

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

CVFWCapture cap;
PBITMAPINFO pBitmap;
ULONG BitmapSize;

cap.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 (cap.CaptureDIB(&pBitmap, 0, &BitmapSize))
{
  // pBitmap captured successfully. Do whatever with it.

  delete pBitmap;    // Delete it when done.
}

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


About the Author

Audrey Mbogho

I am a senior lecturer of computer science at the University of Cape Town and I program in Java now.

Downloads