Error when compiling the DSRender.cpp file from the MS DirectShow Book

Hi, I typed the program from chapter 3 of the book Programming Microsoft Directshow for Digital Video and Processing in VS 2008. Theproject was a C++ project. I created a new .cpp file called DSRender.cpp. Then added the additional dependencies Strmiids.lib and Quartz.lib

The code:
// DSRender.cpp
// A very simple program to render media files using DirectShow
//
#include <windows.h>
#include <dshow.h>
#include <stdio.h>
#include <strsafe.h>

int main(int argc, char* argv)
{
IGraphBuilder *pGraph = NULL; // Graph builder interface
IMediaControl *pControl = NULL; // Media control interface
IMediaEvent *pEvent = NULL; // Media event interface

if (!GetMediaFileName()) { // Local function to get a file name
return(0); // If we didn’t get it, exit
}

// Initialize the COM library.
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
// We’ll send our error messages to the console.
printf(“ERROR - Could not initialize COM library”);
return hr;
}

// Create the Filter Graph Manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void )&pGraph);
if (FAILED(hr)) // FAILED is a macro that tests the return value
{
printf(“ERROR - Could not create the Filter Graph Manager.”);
return hr;
}

// Use IGraphBuilder::QueryInterface (inherited from IUnknown)
// to get the IMediaControl interface.
hr = pGraph->QueryInterface(IID_IMediaControl, (void
)&pControl);
if (FAILED(hr))
{
printf(“ERROR - Could not obtain the Media Control interface.”);
pGraph->Release(); // Clean up after ourselves
pGraph = NULL;
CoUninitialize(); // And uninitialize COM
return hr;
}

// And get the Media Event interface, too.
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
if (FAILED(hr))
{
printf(“ERROR - Could not obtain the Media Event interface.”);
pGraph->Release(); // Clean up after ourselves
pControl->Release();
CoUninitialize(); // And uninitialize COM
return hr;
}

// To build the filter graph, only one call is required.
// We make the RenderFile call to the Filter Graph Manager
// to which we pass the name of the media file.
#ifndef UNICODE
WCHAR wFileName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, g_PathFileName, -1, wFileName,
MAX_PATH);
// This is all that’s required to create a filter graph
// that will render a media file!
hr = pGraph->RenderFile((LPCWSTR)wFileName, NULL);
#else
hr = pGraph->RenderFile((LPCWSTR)g_PathFileName, NULL);
#endif

if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);

// Note: Do not use INFINITE in a real application
// because it can block indefinitely.
}

// And stop the filter graph.
hr = pControl->Stop();

// Before we finish, save the filter graph to a file.
SaveGraphFile(pGraph, L"C:\MyGraph.GRF");
}

// Now release everything and clean up.
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();

return 0;
}

Then I compiled it and I got the following ERRORS:

Error 3 error C3861: ‘SaveGraphFile’: identifier not found c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 92 DS01
Error 1 error C3861: ‘GetMediaFileName’: identifier not found c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 15 DS01
Error 2 error C2065: ‘g_PathFileName’ : undeclared identifier c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 65 DS01

NOTE: I compiled some Directshow samples from the windows SDK and they worked perfectly.

Any help is appreciaated. Do I need to included a header file ?

Many Thanks</strsafe.h></stdio.h></dshow.h></windows.h>

Well, at least in the case of ‘g_PathFileName,’ you didn’t declare it.

mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, June 28, 2010 5:09 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Error when compiling the DSRender.cpp file from the MS
DirectShow Book

Hi, I typed the program from chapter 3 of the book Programming Microsoft
Directshow for Digital Video and Processing in VS 2008. Theproject was a C++
project. I created a new .cpp file called DSRender.cpp. Then added the
additional dependencies Strmiids.lib and Quartz.lib

The code:
// DSRender.cpp
// A very simple program to render media files using DirectShow // #include
<windows.h> #include <dshow.h> #include <stdio.h> #include <strsafe.h>

int main(int argc, char* argv)
{
IGraphBuilder *pGraph = NULL; // Graph builder interface
IMediaControl *pControl = NULL; // Media control interface
IMediaEvent *pEvent = NULL; // Media event interface

if (!GetMediaFileName()) { // Local function to get a file name
return(0); // If we didn’t get it, exit
}

// Initialize the COM library.
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
// We’ll send our error messages to the console.
printf(“ERROR - Could not initialize COM library”);
return hr;
}

// Create the Filter Graph Manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void )&pGraph);
if (FAILED(hr)) // FAILED is a macro that tests the return value
{
printf(“ERROR - Could not create the Filter Graph Manager.”);
return hr;
}

// Use IGraphBuilder::QueryInterface (inherited from IUnknown)
// to get the IMediaControl interface.
hr = pGraph->QueryInterface(IID_IMediaControl, (void
)&pControl);
if (FAILED(hr))
{
printf(“ERROR - Could not obtain the Media Control interface.”);
pGraph->Release(); // Clean up after
ourselves
pGraph = NULL;
CoUninitialize(); // And uninitialize COM
return hr;
}

// And get the Media Event interface, too.
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
if (FAILED(hr))
{
printf(“ERROR - Could not obtain the Media Event interface.”);
pGraph->Release(); // Clean up after ourselves
pControl->Release();
CoUninitialize(); // And uninitialize COM
return hr;
}

// To build the filter graph, only one call is required.
// We make the RenderFile call to the Filter Graph Manager
// to which we pass the name of the media file.
#ifndef UNICODE
WCHAR wFileName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, g_PathFileName, -1, wFileName,
MAX_PATH);
// This is all that’s required to create a filter graph
// that will render a media file!
hr = pGraph->RenderFile((LPCWSTR)wFileName, NULL); #else
hr = pGraph->RenderFile((LPCWSTR)g_PathFileName, NULL); #endif

if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);

// Note: Do not use INFINITE in a real application
// because it can block indefinitely.
}

// And stop the filter graph.
hr = pControl->Stop();

// Before we finish, save the filter graph to a file.
SaveGraphFile(pGraph, L"C:\MyGraph.GRF");
}

// Now release everything and clean up.
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();

return 0;
}

Then I compiled it and I got the following ERRORS:

Error 3 error C3861: ‘SaveGraphFile’: identifier not found
c:\documents and settings\tlna\my documents\visual studio
2008\projects\ds01\ds01\dsrender.cpp 92 DS01
Error 1 error C3861: ‘GetMediaFileName’: identifier not found
c:\documents and settings\tlna\my documents\visual studio
2008\projects\ds01\ds01\dsrender.cpp 15 DS01
Error 2 error C2065: ‘g_PathFileName’ : undeclared identifier
c:\documents and settings\tlna\my documents\visual studio
2008\projects\ds01\ds01\dsrender.cpp 65 DS01

NOTE: I compiled some Directshow samples from the windows SDK and they
worked perfectly.

Any help is appreciaated. Do I need to included a header file ?

Many Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</strsafe.h></stdio.h></dshow.h></windows.h>

You wrote:

Hi, I typed the program from chapter 3 of the book Programming Microsoft Directshow for Digital Video and Processing in VS 2008. Theproject was a C++ project. I created a new .cpp file called DSRender.cpp. Then added the additional dependencies Strmiids.lib and Quartz.lib
...
Then I compiled it and I got the following ERRORS:

Error 3 error C3861: 'SaveGraphFile': identifier not found c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 92 DS01
Error 1 error C3861: 'GetMediaFileName': identifier not found c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 15 DS01
Error 2 error C2065: 'g_PathFileName' : undeclared identifier c:\documents and settings\tlna\my documents\visual studio 2008\projects\ds01\ds01\dsrender.cpp 65 DS01

NOTE: I compiled some Directshow samples from the windows SDK and they worked perfectly.

Any help is appreciaated. Do I need to included a header file ?

You should have been able to figure these out for yourself. SaveGraphFile comes from "dshowutil.h", which is included with DirectShow. Until the most recent SDK, you needed to compile "dshowutil.cpp" as well to satisfy these; in the latest SDK, these utility functions are all inline in "dshowutil.h"

GetMediaFileName and g_PathFileName are copied from other places in the book.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

The follow is the source code of the SaveGraphFile function, I get it from dshowutil.cpp.
You should build the ‘BaseClasses’ before your projects, And add the header file(dshowutil.h) in your project

HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath)
{
if (pGraph == NULL)
{
return E_POINTER;
}

const WCHAR wszStreamName = L"ActiveMovieGraph";

IStorage *pStorage = NULL;
IStream *pStream = NULL;
IPersistStream *pPersist = NULL;

HRESULT hr = StgCreateDocfile(
wszPath,
STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
0, &pStorage);

if(SUCCEEDED(hr))
{
hr = pStorage->CreateStream(
wszStreamName,
STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
0,
0,
&pStream);
}

if (SUCCEEDED(hr))
{
hr = pGraph->QueryInterface(IID_IPersistStream, (void**)&pPersist);
}

if (SUCCEEDED(hr))
{
hr = pPersist->Save(pStream, TRUE);
}

if (SUCCEEDED(hr))
{
hr = pStorage->Commit(STGC_DEFAULT);
}

SAFE_RELEASE(pStorage);
SAFE_RELEASE(pStream);
SAFE_RELEASE(pPersist);

return hr;
}