我的第一个DirectShow程序,播放一段视频

1、创建一个win32程序。

2、加入头文件  

#include <DShow.h>

3、包含库文件

#pragma comment(lib,"Strmiids.lib")

4、写代码:

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

	HRESULT hr = CoInitialize(NULL);
	if (FAILED(hr))
	{
		return -1;
	}

	hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void **)&pGraph);

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

	hr = pGraph->RenderFile(L"D:\\工作项目文件夹\\视频专项\\各类测试视频\\185200.avi",NULL);
	if (SUCCEEDED(hr))
	{
		hr = pControl->Run();
		if (SUCCEEDED(hr))
		{
			long evCode=0;
			pEvent->WaitForCompletion(INFINITE,&evCode);
		}
	}
	pControl->Release();
	pEvent->Release();
	pGraph->Release();
	CoUninitialize();

5、运行,ok!


参考文章地址:

http://www.cppblog.com/wform/archive/2006/10/17/13783.html

工程下载(vs2010 sdk7.1 win7_x64):

http://download.csdn.net/detail/cau_eric/6820327

你可能感兴趣的:(编程,windows,VS2010,Visual,Studio,2010,directshow)