開發(fā)環(huán)境
SDK:DirectX9.0b (Summer 2003)
Visual C++ 6.0
參考文檔:SDK文檔
1) DirectShow->Getting Started->Setting Up the Build Environment
2) DirectShow->DirectShow Reference->DirectShow Base Classes->Using the DirectShow Base Classes
3) DirectShow->Getting Started->How To Play?a File
測試例子:SDK文檔
DirectShow->Getting Started->How To Play a File
配置說明:
1. Tools->Options->Directories
Include - 添加<SDK root>\Include
Lib?????? - 添加<SDK root>\Lib
??????????? - 添加<SDK root>\SAMPLES\C++\DirectShow\BASECLASSES\DEBUG? // [注1]
2. Build BaseClasses
打開<SDK root>\Samples\C++\DirectShow\BaseClasses\baseclasses.dsp,編譯debug得到Strmbasd.lib。 // [注2]
3. Project->Setting->Link
添加Strmbasd.lib
4. 添加頭文件
#include <Dshow.h>??????? // 所有DirectShow應用程序必備
#include <Streams.h>??????// 使用DirectShow基類
源代碼如下,代碼分析見參考文檔3)
#include?<Dshow.h>
#include?<Streams.h>
#include?<stdio.h>

void?main(void)


{
????IGraphBuilder?*pGraph?=?NULL;
????IMediaControl?*pControl?=?NULL;
????IMediaEvent???*pEvent?=?NULL;

????//?Initialize?the?COM?library.
????HRESULT?hr?=?CoInitialize(NULL);
????if?(FAILED(hr))

????
{
????????printf("ERROR?-?Could?not?initialize?COM?library");
????????return;
????}

????//?Create?the?filter?graph?manager?and?query?for?interfaces.
????hr?=?CoCreateInstance(CLSID_FilterGraph,?NULL,?CLSCTX_INPROC_SERVER,?
????????????????????????IID_IGraphBuilder,?(void?**)&pGraph);
????if?(FAILED(hr))

????
{
????????printf("ERROR?-?Could?not?create?the?Filter?Graph?Manager.");
????????return;
????}

????hr?=?pGraph->QueryInterface(IID_IMediaControl,?(void?**)&pControl);
????hr?=?pGraph->QueryInterface(IID_IMediaEvent,?(void?**)&pEvent);

????//?Build?the?graph.?IMPORTANT:?Change?this?string?to?a?file?on?your?system.
//????hr?=?pGraph->RenderFile(L"C:\\Example.avi",?NULL);
????hr?=?pGraph->RenderFile(L"E:\\DX90SDK\\Samples\\Media\\chicken.wmv",?NULL); // 打開一個媒體文件
????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.
????????}
????}
????pControl->Release();
????pEvent->Release();
????pGraph->Release();
????CoUninitialize();
}

注1:該處可根據(jù)需要添加不同版本,如RELEASE/Debug_Unicode/Release_Unicode。
注2:debug?- strmbasd.lib;release - strmbase.lib;另外還有對應的Unicode版本。
注3:步驟3缺,將導致
error LNK2001: unresolved external symbol _IID_IMediaEvent
error LNK2001: unresolved external symbol _IID_IMediaControl
error LNK2001: unresolved external symbol _CLSID_FilterGraph
error LNK2001: unresolved external symbol _IID_IGraphBuilder
Debug/Howtoplayafile.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
posted on 2006-10-17 17:49
夜舞重金屬 閱讀(6440)
評論(5) 編輯 收藏 引用 所屬分類:
DirectShow