配置步骤:
1) 安装directX sdk
2)打开安装目录下“../Samples/C++/DirectShow/BaseClasses/baseclasses.dsw" 编译它,成功后会生成“Debug_Unicode”目录,里面有我们需要的库“strmbasd.lib”
3)在VC++的Tools/Option/Directory的Include和Library中分别加入
Include:
C:/DXSDK/Include
C:/DXSDK/SAMPLES/C++/DIRECTSHOW/BASECLASSES
C:/DXSDK/SAMPLES/C++/COMMON/INCLUDE
Libarary:
C:/DXSDK/Lib
C:/DXSDK/SAMPLES/C++/DIRECTSHOW/BASECLASSES/DEBUG
注意一定要把directx的include文件和lib文件目录顺序提到最前
4)在Project/Setting/Link/ 中加入 strmbasd.lib uuid.lib winmm.lib
实例:
打开vc创建一个控制台程序,按上面步骤配置好环境,输入一下代码:
#include <stdafx.h>
#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); // 打开一个媒体文件
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();
}