Click here to Skip to main content
Click here to Skip to main content

WDM / VFW ...my definitive solution...

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

Introduction   

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"  

or

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

 or  

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

 or   

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
cap->StartPreview();  

...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.


License

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

Share

About the Author

No Biography provided

Comments and Discussions

 
GeneralMy vote of 4 PinprofessionalAmir Mohammad Nasrollahi20-Aug-13 6:18 
GeneralRe: My vote of 4 PinmemberFabio Durigon20-Aug-13 7:15 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 20 Aug 2013
Article Copyright 2013 by Fabio Durigon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid