第一个DirectShow程序

长平狐 发布于 2012/11/12 11:50
阅读 120
收藏 1

 1: // DShowTest.cpp : 定义控制台应用程序的入口点。
 2: //
 3: 
 4: #include "stdafx.h"
 5: 
 6: 
 7: #include <dshow.h>
 8: void main(void)
 9: {
10: 	IGraphBuilder *pGraph = NULL;
11: 	IMediaControl *pControl = NULL;
12: 	IMediaEvent   *pEvent = NULL;
13: 
14: 	// Initialize the COM library.
15: 	HRESULT hr = CoInitialize(NULL);
16: 	if (FAILED(hr))
17: 	{
18: 		printf("ERROR - Could not initialize COM library");
19: 		return;
20: 	}
21: 
22: 	// Create the filter graph manager and query for interfaces.
23: 	hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
24: 		IID_IGraphBuilder, (void **)&pGraph);
25: 	if (FAILED(hr))
26: 	{
27: 		printf("ERROR - Could not create the Filter Graph Manager.");
28: 		return;
29: 	}
30: 
31: 	hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
32: 	hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
33: 
34: 	// Build the graph. IMPORTANT: Change this string to a file on your system.
35: 	hr = pGraph->RenderFile(L"D://TDDOWNLOAD//Movie//回梦游仙-千年缘.avi", NULL);
36: 	if (SUCCEEDED(hr))
37: 	{
38: 		// Run the graph.
39: 		hr = pControl->Run();
40: 		if (SUCCEEDED(hr))
41: 		{
42: 			// Wait for completion.
43: 			long evCode;
44: 			pEvent->WaitForCompletion(INFINITE, &evCode);
45: 
46: 			// Note: Do not use INFINITE in a real application, because it
47: 			// can block indefinitely.
48: 		}
49: 	}
50: 	pControl->Release();
51: 	pEvent->Release();
52: 	pGraph->Release();
53: 	CoUninitialize();
54: }
 


原文链接:http://blog.csdn.net/xoyojank/article/details/2582819
加载中
返回顶部
顶部