Tim,
Please copy my PRG to FWH\samples\dshow.prg and do buildh32.bat dshow
Thats how I am testing it here
Tim,
Please copy my PRG to FWH\samples\dshow.prg and do buildh32.bat dshow
Thats how I am testing it here
Are these still Borland builds ? I still cannot get it to compile with MSVC 2015
Tim
I am using MSVC 2015 Community Edition
do samples\buildh32.bat dshow
going to bed ![]()
I'm getting an error at line 5, and the a has an ' over it.
Lines 4861, Functions/Procedures 1
Generating C source output to 'dshow.c'... Done.
dshow.c
dshow.prg(22): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(22): error C2065: '每': undeclared identifier
dshow.prg(22): error C2146: syntax error: missing ';' before identifier '每HRESULT'
dshow.prg(22): error C2065: '每HRESULT': undeclared identifier
dshow.prg(22): error C2146: syntax error: missing ';' before identifier 'hr'
dshow.prg(22): error C2065: 'hr': undeclared identifier
dshow.prg(23): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(23): error C2065: '每': undeclared identifier
dshow.prg(23): error C2146: syntax error: missing ';' before identifier '每ICreateDevEnum'
dshow.prg(23): error C2065: '每ICreateDevEnum': undeclared identifier
dshow.prg(23): error C2065: 'pDevEnum': undeclared identifier
dshow.prg(24): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(24): error C2065: '每': undeclared identifier
dshow.prg(24): error C2146: syntax error: missing ';' before identifier '每IEnumMoniker'
dshow.prg(24): error C2065: '每IEnumMoniker': undeclared identifier
dshow.prg(24): error C2065: 'pEnum': undeclared identifier
dshow.prg(25): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(25): error C2065: '每': undeclared identifier
dshow.prg(25): error C2146: syntax error: missing ';' before identifier '每IMoniker'
dshow.prg(25): error C2065: '每IMoniker': undeclared identifier
dshow.prg(25): error C2065: 'pMoniker': undeclared identifier
dshow.prg(26): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(26): error C2065: '每': undeclared identifier
dshow.prg(26): error C2146: syntax error: missing ';' before identifier '每IPropertyBag'
dshow.prg(26): error C2065: '每IPropertyBag': undeclared identifier
dshow.prg(26): error C2065: 'pPropBag': undeclared identifier
dshow.prg(27): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(27): error C2065: '每': undeclared identifier
dshow.prg(27): error C2146: syntax error: missing ';' before identifier '每IGraphBuilder'
dshow.prg(27): error C2065: '每IGraphBuilder': undeclared identifier
dshow.prg(27): error C2065: 'pGraph': undeclared identifier
dshow.prg(28): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(28): error C2065: '每': undeclared identifier
dshow.prg(28): error C2146: syntax error: missing ';' before identifier '每ICaptureGraphBuilder2'
dshow.prg(28): error C2065: '每ICaptureGraphBuilder2': undeclared identifier
dshow.prg(28): error C2065: 'pBuilder': undeclared identifier
dshow.prg(29): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(29): error C2065: '每': undeclared identifier
dshow.prg(29): error C2146: syntax error: missing ';' before identifier '每IBaseFilter'
dshow.prg(29): error C2065: '每IBaseFilter': undeclared identifier
dshow.prg(29): error C2065: 'pCap': undeclared identifier
dshow.prg(30): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(30): error C2065: '每': undeclared identifier
dshow.prg(30): error C2146: syntax error: missing ';' before identifier '每IBaseFilter'
dshow.prg(30): error C2065: '每IBaseFilter': undeclared identifier
dshow.prg(30): error C2065: 'pSampleGrabberFilter': undeclared identifier
dshow.prg(31): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(31): error C2065: '每': undeclared identifier
dshow.prg(31): error C2146: syntax error: missing ';' before identifier '每IBaseFilter'
dshow.prg(31): error C2065: '每IBaseFilter': undeclared identifier
dshow.prg(31): error C2065: 'pNullRenderer': undeclared identifier
dshow.prg(32): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(32): error C2065: '每': undeclared identifier
dshow.prg(32): error C2146: syntax error: missing ';' before identifier '每IMediaControl'
dshow.prg(32): error C2065: '每IMediaControl': undeclared identifier
dshow.prg(32): error C2065: 'pMediaControl': undeclared identifier
dshow.prg(33): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(33): error C2065: '每': undeclared identifier
dshow.prg(33): error C2146: syntax error: missing ';' before identifier '每char'
dshow.prg(33): error C2065: '每char': undeclared identifier
dshow.prg(33): error C2065: 'pBuffer': undeclared identifier
dshow.prg(34): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(34): error C2065: '每': undeclared identifier
dshow.prg(34): error C2146: syntax error: missing ';' before identifier '每VARIANT'
dshow.prg(34): error C2065: '每VARIANT': undeclared identifier
dshow.prg(34): error C2146: syntax error: missing ';' before identifier 'var'
dshow.prg(34): error C2065: 'var': undeclared identifier
dshow.prg(35): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(35): error C2065: '每': undeclared identifier
dshow.prg(35): error C2146: syntax error: missing ';' before identifier '每'
dshow.prg(35): error C2144: syntax error: 'int' should be preceded by ';'
dshow.prg(36): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(36): error C2065: '每': undeclared identifier
dshow.prg(36): error C2146: syntax error: missing ';' before identifier '每'
dshow.prg(36): error C2144: syntax error: 'int' should be preceded by ';'
dshow.prg(37): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(37): error C2065: '每': undeclared identifier
dshow.prg(37): error C2146: syntax error: missing ';' before identifier '每'
dshow.prg(37): error C2144: syntax error: 'char' should be preceded by ';'
dshow.prg(38): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(38): error C2065: '每': undeclared identifier
dshow.prg(38): error C2146: syntax error: missing ';' before identifier '每char'
dshow.prg(38): error C2065: '每char': undeclared identifier
dshow.prg(38): error C2146: syntax error: missing ';' before identifier 'char_buffer'
dshow.prg(38): error C2065: 'char_buffer': undeclared identifier
dshow.prg(39): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(39): error C2653: '每DexterLib': is not a class or namespace name
dshow.prg(39): error C2065: '每': undeclared identifier
dshow.prg(39): error C2146: syntax error: missing ';' before identifier 'ISampleGrabber'
dshow.prg(39): error C2065: 'ISampleGrabber': undeclared identifier
dshow.prg(39): error C2065: 'pSampleGrabber': undeclared identifier
dshow.prg(41): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(41): error C2065: '每': undeclared identifier
dshow.prg(41): error C2146: syntax error: missing ';' before identifier '每strcpy'
dshow.prg(41): error C3861: '每strcpy': identifier not found
dshow.prg(43): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(43): error C2065: '每': undeclared identifier
dshow.prg(43): error C2146: syntax error: missing ';' before identifier '每hr'
dshow.prg(43): error C2065: '每hr': undeclared identifier
dshow.prg(45): error C3873: '0xa0': this character is not allowed as a first character of an identifier
dshow.prg(45): error C2065: '每': undeclared identifier
dshow.prg(45): fatal error C1003: error count exceeds 100; stopping compilation
LINK : fatal error LNK1181: cannot open input file 'dshow.obj'
* Linking errors *Antonio,
I am able to get this to compile and run using VS 2015, but I needed to do/change a couple things:
1) Explicitly set to compile as CPP code instead of C.
2) Changed MessageBox() calls to MessageBoxA() to get around a unicode/casting error.
Robb,
Yes, it has to be compiled in C++ mode
FWH\samples\buildh32.bat does it automatically
> 2) Changed MessageBox() calls to MessageBoxA() to get around a unicode/casting error
that may be as you are using unicode at compiling time.
buildh32.bat works fine and does not use unicode
One other thing I forgot is I had to add "strmiids" to my list of libs to resolve a bunch of unresolved externals. I don't see that lib referenced in buildh32.bat so I'm not sure why I see the missing externals and you don't.
I am able to get it to run both as 32 and 64 bit.
Robb,
I mentioned here that strmiids.lib has to be linked:
viewtopic.php?p=193422#p193422
many thanks for your feedback
#include "FiveWin.ch"
function Main()
local oWnd, hWnd
DEFINE WINDOW oWnd
ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT ( DShowCamera(),;
SetParent( hWnd := FindWindow( 0, "ActiveMovie Window" ), oWnd:hWnd ),;
SetWindowPos( hWnd, 0, 10, 10, 300, 300 ) )
return nil
#pragma BEGINDUMP
#include <dshow.h>
#include <uuids.h>
#include <objbase.h>
#import "qedit.dll" raw_interfaces_only named_guids
EXTERN_C const CLSID CLSID_NullRenderer;
EXTERN_C const CLSID CLSID_SampleGrabber;
HB_FUNC( DSHOWCAMERA )
{
HRESULT hr;
ICreateDevEnum *pDevEnum = NULL;
IEnumMoniker *pEnum = NULL;
IMoniker *pMoniker = NULL;
IPropertyBag *pPropBag = NULL;
IGraphBuilder *pGraph = NULL;
ICaptureGraphBuilder2 *pBuilder = NULL;
IBaseFilter *pCap = NULL;
IBaseFilter *pSampleGrabberFilter = NULL;
IBaseFilter *pNullRenderer = NULL;
IMediaControl *pMediaControl = NULL;
char *pBuffer = NULL;
VARIANT var;
int n = 0;
int device_number = 0;
char device_name[ 100 ];
char char_buffer[100];
DexterLib::ISampleGrabber *pSampleGrabber = NULL;
strcpy( device_name, "" );
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if( hr != S_OK )
MessageBox( 0, "CoInitializeEx error", "ok", 0 );
hr = CoCreateInstance( CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
( void ** ) &pGraph );
if( hr != S_OK )
MessageBox( 0, "CoCreateInstance error", "ok", 0 );
hr = CoCreateInstance( CLSID_CaptureGraphBuilder2, NULL,
CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
( void ** ) &pBuilder );
if( hr != S_OK )
MessageBox( 0, "CoCreateInstance 2 error", "ok", 0 );
hr = ( ( ICaptureGraphBuilder * ) pBuilder )->SetFiltergraph( pGraph );
if( hr != S_OK )
MessageBox( 0, "Could not attach capture graph builder to graph", "ok", 0 );
hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pDevEnum ) );
if( hr != S_OK )
MessageBox( 0, "Could not crerate system device enumerator", "ok", 0 );
hr = pDevEnum->CreateClassEnumerator(
CLSID_VideoInputDeviceCategory, &pEnum, 0 );
if( hr != S_OK )
MessageBox( 0, "No video devices found", "ok", 0 );
while(1)
{
// Access next device
hr = pEnum->Next(1, &pMoniker, NULL);
if( hr == S_OK )
n++; // increment device count
else
break;
// If device was specified by name rather than number...
if( device_number == 0 )
{
// Get video input device name
hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
if (hr == S_OK)
{
// Get current device name
VariantInit(&var);
hr = pPropBag->Read(L"FriendlyName", &var, 0);
// Convert to a normal C string, i.e. char*
sprintf(char_buffer, "%ls", var.bstrVal);
VariantClear(&var);
pPropBag->Release();
pPropBag = NULL;
// Exit loop if current device name matched devname
// MessageBox( 0, char_buffer, "device_name", 0 );
if (strcmp(device_name, char_buffer) == 0) break;
}
else
{
MessageBox( 0, "Error getting device names", "ok", 0 );
break;
}
}
else if (n >= device_number) break;
}
// Get video input device name
hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
VariantInit(&var);
hr = pPropBag->Read(L"FriendlyName", &var, 0);
// MessageBoxW( 0, L"Capture device", var.bstrVal, 0 );
VariantClear(&var);
// Create capture filter and add to graph
hr = pMoniker->BindToObject(0, 0,
IID_IBaseFilter, (void**)&pCap);
if( hr != S_OK )
MessageBox( 0, "Could not create capture filter", "ok", 0 );
// Add capture filter to graph
hr = pGraph->AddFilter(pCap, L"Capture Filter");
if( hr != S_OK )
MessageBox( 0, "Could not add capture filter to graph", "ok", 0 );
// Create sample grabber filter
hr = CoCreateInstance(CLSID_SampleGrabber, NULL,
CLSCTX_INPROC_SERVER, IID_IBaseFilter,
(void**)&pSampleGrabberFilter);
if( hr != S_OK )
MessageBox( 0, "Could not create Sample Grabber filter", "ok", 0 );
// Query the ISampleGrabber interface of the sample grabber filter
hr = pSampleGrabberFilter->QueryInterface(
DexterLib::IID_ISampleGrabber, (void**)&pSampleGrabber);
if( hr != S_OK )
MessageBox( 0, "Could not get ISampleGrabber interface to sample grabber filter", "ok", 0 );
// Enable sample buffering in the sample grabber filter
hr = pSampleGrabber->SetBufferSamples(TRUE);
if( hr != S_OK )
MessageBox( 0, "Could not enable sample buffering in the sample grabber", "ok", 0 );
// Set media type in sample grabber filter
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
hr = pSampleGrabber->SetMediaType((DexterLib::_AMMediaType *)&mt);
if( hr != S_OK )
MessageBox( 0, "Could not set media type in sample grabber", "ok", 0 );
// Add sample grabber filter to filter graph
hr = pGraph->AddFilter(pSampleGrabberFilter, L"SampleGrab");
if( hr != S_OK )
MessageBox( 0, "Could not add Sample Grabber to filter graph", "ok", 0 );
// Create Null Renderer filter
hr = CoCreateInstance(CLSID_NullRenderer, NULL,
CLSCTX_INPROC_SERVER, IID_IBaseFilter,
(void**)&pNullRenderer);
if( hr != S_OK )
MessageBox( 0, "Could not create Null Renderer filter", "ok", 0 );
// Add Null Renderer filter to filter graph
hr = pGraph->AddFilter(pNullRenderer, L"NullRender");
if( hr != S_OK )
MessageBox( 0, "Could not add Null Renderer to filter graph", "ok", 0 );
// Connect up the filter graph's capture stream
hr = pBuilder->RenderStream(
&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
pCap, pSampleGrabberFilter, pNullRenderer);
if( hr != S_OK )
MessageBox( 0, "Could not render capture video stream", "ok", 0 );
hr = pBuilder->RenderStream(
&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
pCap, NULL, NULL);
if (hr != S_OK && hr != VFW_S_NOPREVIEWPIN)
MessageBox( 0, "Could not render preview video stream", "ok", 0 );
// Get media control interfaces to graph builder object
hr = pGraph->QueryInterface(IID_IMediaControl,
(void**)&pMediaControl);
if( hr != S_OK )
MessageBox( 0, "Could not get media control interface", "ok", 0 );
// Run graph
while(1)
{
hr = pMediaControl->Run();
// Hopefully, the return value was S_OK or S_FALSE
if (hr == S_OK) break; // graph is now running
if (hr == S_FALSE) continue; // graph still preparing to run
// If the Run function returned something else,
// there must be a problem
// fprintf(stderr, "Error: %u\n", hr);
MessageBox( 0, "Could not run filter graph", "ok", 0 );
}
}
#pragma ENDDUMP#include "FiveWin.ch"
#define GWL_STYLE -16
function Main()
聽 聽local oWnd, hWnd
聽 聽
聽 聽DEFINE WINDOW oWnd
聽 聽ACTIVATE WINDOW oWnd MAXIMIZED ;
聽 聽 聽 ON INIT ( DShowCamera(),;
聽 聽 聽 聽 聽 聽 聽 聽 SetParent( hWnd := FindWindow( 0, "ActiveMovie Window" ), oWnd:hWnd ),;
聽 聽 聽 聽 聽 聽 聽 聽 SetWindowLong( hWnd, GWL_STYLE, nOr( WS_CHILD, WS_VISIBLE ) ),;
聽 聽 聽 聽 聽 聽 聽 聽 SetWindowPos( hWnd, 0, 10, 10, 300, 300 ) )
return nil
#pragma BEGINDUMP
#include <dshow.h>
#include <uuids.h>
#include <objbase.h>
#import "qedit.dll" raw_interfaces_only named_guids
EXTERN_C const CLSID CLSID_NullRenderer;
EXTERN_C const CLSID CLSID_SampleGrabber;
HB_FUNC( DSHOWCAMERA )
{
聽 聽HRESULT hr;
聽 聽ICreateDevEnum *pDevEnum = NULL;
聽 聽IEnumMoniker *pEnum = NULL;
聽 聽IMoniker *pMoniker = NULL;
聽 聽IPropertyBag *pPropBag = NULL;
聽 聽IGraphBuilder *pGraph = NULL;
聽 聽ICaptureGraphBuilder2 *pBuilder = NULL;
聽 聽IBaseFilter *pCap = NULL;
聽 聽IBaseFilter *pSampleGrabberFilter = NULL;
聽 聽IBaseFilter *pNullRenderer = NULL;
聽 聽IMediaControl *pMediaControl = NULL;
聽 聽char *pBuffer = NULL;
聽 聽VARIANT var;
聽 聽 int n = 0;
聽 聽 int device_number = 0;
聽 聽 char device_name[ 100 ];
聽 聽char char_buffer[100];
聽 聽DexterLib::ISampleGrabber *pSampleGrabber = NULL;
聽 聽strcpy( device_name, "" );
聽 聽hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
聽 聽if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "CoInitializeEx error", "ok", 0 );
聽 聽hr = CoCreateInstance( CLSID_FilterGraph, NULL,
聽聽 聽聽 聽 聽 聽 聽 CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
聽 聽 聽 聽 聽 聽 聽 ( void ** ) &pGraph );
聽 聽 聽 聽 聽 聽
聽 聽if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "CoCreateInstance error", "ok", 0 );
聽 聽 聽
聽 聽 hr = CoCreateInstance( CLSID_CaptureGraphBuilder2, NULL,
聽 聽 聽 聽 聽 聽 CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
聽 聽 聽 聽 聽 聽 ( void ** ) &pBuilder ); 聽 聽 聽
聽 聽if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "CoCreateInstance 2 error", "ok", 0 );
聽 聽 hr = ( ( ICaptureGraphBuilder * ) pBuilder )->SetFiltergraph( pGraph );
聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not attach capture graph builder to graph", "ok", 0 );
聽 聽 聽
聽 聽 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL,
聽 聽 聽 聽 聽 聽 CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pDevEnum ) );
聽 聽 聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not crerate system device enumerator", "ok", 0 );
聽 聽 聽
聽 聽 hr = pDevEnum->CreateClassEnumerator(
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 CLSID_VideoInputDeviceCategory, &pEnum, 0 );
聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "No video devices found", "ok", 0 ); 聽 聽 聽
聽 聽 聽
聽 聽 while(1)
聽 聽 {
聽 聽 聽 聽 // Access next device
聽 聽 聽 聽 hr = pEnum->Next(1, &pMoniker, NULL);
聽 聽 聽 聽 if( hr == S_OK )
聽 聽 聽 聽 聽 聽 n++; // increment device count
聽 聽 聽 else 聽
聽 聽 聽 聽 聽break;
聽 聽 聽 聽
聽 聽 聽 聽 // If device was specified by name rather than number...
聽 聽 聽 聽 if( device_number == 0 )
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 // Get video input device name
聽 聽 聽 聽 聽 聽 hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
聽 聽 聽 聽 聽 聽 if (hr == S_OK)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 // Get current device name
聽 聽 聽 聽 聽 聽 聽 聽 VariantInit(&var);
聽 聽 聽 聽 聽 聽 聽 聽 hr = pPropBag->Read(L"FriendlyName", &var, 0);
聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 聽 聽 // Convert to a normal C string, i.e. char*
聽 聽 聽 聽 聽 聽 聽 聽 sprintf(char_buffer, "%ls", var.bstrVal);
聽 聽 聽 聽 聽 聽 聽 聽 VariantClear(&var);
聽 聽 聽 聽 聽 聽 聽 聽 pPropBag->Release();
聽 聽 聽 聽 聽 聽 聽 聽 pPropBag = NULL;
聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 聽 聽 // Exit loop if current device name matched devname
聽 聽 聽 聽 聽 聽 // MessageBox( 0, char_buffer, "device_name", 0 );
聽 聽 聽 聽 聽 聽
聽 聽 聽 聽 聽 聽 聽 聽 if (strcmp(device_name, char_buffer) == 0) break;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 else
聽 聽 聽 聽 聽{
聽 聽 聽 聽 聽 聽 聽 聽 MessageBox( 0, "Error getting device names", "ok", 0 );
聽 聽 聽 聽 聽 聽 break;
聽 聽 聽 聽 聽} 聽
聽 聽 聽 聽 }
聽 聽 聽 聽 else if (n >= device_number) break;
聽 聽 } 聽
聽 聽
聽 聽 // Get video input device name
聽 聽 hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
聽 聽 VariantInit(&var);
聽 聽 hr = pPropBag->Read(L"FriendlyName", &var, 0);
聽 聽 // MessageBoxW( 0, L"Capture device", var.bstrVal, 0 );
聽 聽 VariantClear(&var); 聽
聽 聽
聽 聽 // Create capture filter and add to graph
聽 聽 hr = pMoniker->BindToObject(0, 0,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 IID_IBaseFilter, (void**)&pCap);
聽 聽 聽 聽 聽 聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "Could not create capture filter", "ok", 0 ); 聽
聽 聽 // Add capture filter to graph
聽 聽 hr = pGraph->AddFilter(pCap, L"Capture Filter");
聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "Could not add capture filter to graph", "ok", 0 );
聽 聽 // Create sample grabber filter
聽 聽 hr = CoCreateInstance(CLSID_SampleGrabber, NULL,
聽 聽 聽 聽 CLSCTX_INPROC_SERVER, IID_IBaseFilter,
聽 聽 聽 聽 (void**)&pSampleGrabberFilter);
聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not create Sample Grabber filter", "ok", 0 );
聽 聽 // Query the ISampleGrabber interface of the sample grabber filter
聽 聽 hr = pSampleGrabberFilter->QueryInterface(
聽 聽 聽 聽 聽 聽 DexterLib::IID_ISampleGrabber, (void**)&pSampleGrabber);
聽 聽 聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not get ISampleGrabber interface to sample grabber filter", "ok", 0 );
聽 聽 // Enable sample buffering in the sample grabber filter
聽 聽 hr = pSampleGrabber->SetBufferSamples(TRUE);
聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not enable sample buffering in the sample grabber", "ok", 0 );
聽 聽 // Set media type in sample grabber filter
聽 聽 AM_MEDIA_TYPE mt;
聽 聽 ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
聽 聽 mt.majortype = MEDIATYPE_Video;
聽 聽 mt.subtype = MEDIASUBTYPE_RGB24;
聽 聽 hr = pSampleGrabber->SetMediaType((DexterLib::_AMMediaType *)&mt);
聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not set media type in sample grabber", "ok", 0 );
聽 聽 // Add sample grabber filter to filter graph
聽 聽 hr = pGraph->AddFilter(pSampleGrabberFilter, L"SampleGrab");
聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not add Sample Grabber to filter graph", "ok", 0 );
聽 聽 // Create Null Renderer filter
聽 聽 hr = CoCreateInstance(CLSID_NullRenderer, NULL,
聽 聽 聽 聽 CLSCTX_INPROC_SERVER, IID_IBaseFilter,
聽 聽 聽 聽 (void**)&pNullRenderer);
聽 聽if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not create Null Renderer filter", "ok", 0 );
聽 聽 // Add Null Renderer filter to filter graph
聽 聽 hr = pGraph->AddFilter(pNullRenderer, L"NullRender");
聽 聽if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not add Null Renderer to filter graph", "ok", 0 );
聽 聽 聽
聽 聽// Connect up the filter graph's capture stream
聽 聽 hr = pBuilder->RenderStream(
聽 聽 聽 聽 &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
聽 聽 聽 聽 pCap, 聽pSampleGrabberFilter, pNullRenderer);
聽 聽 聽
聽 聽 if( hr != S_OK )
聽 聽 聽 聽 MessageBox( 0, "Could not render capture video stream", "ok", 0 );
聽 聽 hr = pBuilder->RenderStream(
聽 聽 聽 聽 聽 聽 聽 聽 &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
聽 聽 聽 聽 聽 聽 聽 聽 pCap, NULL, NULL);
聽 聽
聽 聽if (hr != S_OK && hr != VFW_S_NOPREVIEWPIN)
聽 聽 聽 聽 聽 聽 MessageBox( 0, "Could not render preview video stream", "ok", 0 );
聽 聽 // Get media control interfaces to graph builder object
聽 聽 hr = pGraph->QueryInterface(IID_IMediaControl,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 (void**)&pMediaControl);
聽 聽if( hr != S_OK )
聽 聽 聽 MessageBox( 0, "Could not get media control interface", "ok", 0 );
聽 聽 // Run graph
聽 聽 while(1)
聽 聽 {
聽 聽 聽 聽 hr = pMediaControl->Run();
聽 聽 聽 聽
聽 聽 聽 聽 // Hopefully, the return value was S_OK or S_FALSE
聽 聽 聽 聽 if (hr == S_OK) break; // graph is now running
聽 聽 聽 聽 if (hr == S_FALSE) continue; // graph still preparing to run
聽 聽 聽 聽
聽 聽 聽 聽 // If the Run function returned something else,
聽 聽 聽 聽 // there must be a problem
聽 聽 聽 聽 // fprintf(stderr, "Error: %u\n", hr);
聽 聽 聽 聽 MessageBox( 0, "Could not run filter graph", "ok", 0 );
聽 聽 }
}
#pragma ENDDUMP