Click here to Skip to main content
13,829,956 members
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 13 Aug 2013
Licenced CPOL

WDM / VFW definitive solution...

, 20 Aug 2013
Rate this:
Please Sign up or sign in to vote.
A class to handle WDM (Windows Driver Mode).


When I was trying to implement video preview in my programs, I have been found some documentation an example to use VFW (Video For Windows) tecnology and it seems to be more simple than DirectShow and taking some code from here and from there, I wrote my C++ VFW class. But on some Windows version combined with some camera drivers, often, it shows the source selection window instead the preview window and it was impossible to use it. So.... I have decided to start writing another class to handle WDM (Windows Driver Mode).

Finally, I have written two classes, one for VFW and one for WDM. For now this is a basic approach, this code implements only Video Preview (...for now). For writing this classes I used MSDN help and Your help too, so, I hope it can be usefull for who is starting using Video Capture (like me...). Everyone can add features to this class, like video analizing, capturing and so on.

I develope my Windows programs with Builder C++ XE2 compiler but these class are written using the most compatibility win32 api, so, they can be used with any compilers (I hope it).

The peculiarity of this code is that the public functions of both classes are the same, so, You can write only one program to handle VFW of WDM class. 

I have commented the code in Doxygen mode, compiled and added it to the downloadable file, so You can open the index.html page in html folder to consult classes documentation. 

Using the code:

1. Include the header file:   
#include "VfwVideoCap.h"  


#include "WdmVideoCap.h" 
2. Declare a pointer to the class ( I suggest You to declare it global)
DVfwCap *cap; // for vfw class


DWdmCap *cap; // for wdm class

3. Create a class instance, you must specify the handle of the window on which You want to see the preview

cap=new DVfwCap(hWnd); // for vfw class


cap=new DWdmCap(hWnd); // for wdm class 

4. From here You can use the same calls to handle the preview window

// Create the capture window connected to the first camera in the system (if any)
// starting from 0,0 (relative to the window) and 320x240 size in
// the window passed in constructor 
cap->CreateCapWindow(0,        // device index (0 is the first)
                     0,        // X start
                     0,        // Y start
                     320,      // Width
                     240 );    // Height// Start previewing

...That's all, it's easy 

You can also handle the previewing using:
cap->StopPreview(); // To stop previewing
cap->PausePreview() // To pause the preview
cap->SetCapSize(0,0,640,480); // To change the preview size 

before exit program don't forget to destroy the class instance

delete cap; 

List of funcions that can be used in both classes:

int EnumerateVideoCaptureDevices(void);
int EnumerateVideoCompressorDevices(void);
char* GetVideoCaptureDeviceName(unsigned int DeviceId);
char* GetVideoCompressorDeviceName(unsigned int DeviceId);
HRESULT CreateCapWindow(HWND hwndParent, int iDeviceID, int X, int Y, int iWidth, int iHeight);
HRESULT CreateCapWindow(int iDeviceID, int X, int Y, int Width, int Height);
HRESULT CreateCapWindow(void);
HRESULT SetCapSize(int X, int Y, int Width, int Height);
HRESULT SetLowRes(void);
HRESULT SetMidRes(void);
HRESULT SetHiRes(void);
bool StartPreview(void);
bool StopPreview(void);
bool PausePreview(void);
void ShowPreviewWindow(void);
void HidePreviewWindow(void); 

See the class documenation for using its.


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


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Amir Mohammad Nasrollahi20-Aug-13 7:18
professionalAmir Mohammad Nasrollahi20-Aug-13 7:18 
GeneralRe: My vote of 4 Pin
Fabio Durigon20-Aug-13 8:15
memberFabio Durigon20-Aug-13 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190114.1 | Last Updated 20 Aug 2013
Article Copyright 2013 by Fabio Durigon
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid