01.void CShow1Dlg::OnButton1()
02.{
03.// COM库初始化
04.CoInitialize(NULL);
05.
06.
07.// 创建组件对象 Graph(图表,可理解为一个Filter链表)
08.IGraphBuilder *pGraph;
09.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
10. IID_IGraphBuilder, (void **)&pGraph);
11.
12.
13.// 查询得到组件对象上的接口
14.IMediaControl *pMediaControl;
15.pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
16.IMediaEvent *pEvent;
17.pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
18.
19.
20.// 创建 Graph 从一个硬盘文件
21.pGraph->RenderFile(L"d://kk4.mpg", NULL);
22.
23.
24.// 调用接口方法 运行图表
25.pMediaControl->Run();
26.
27.
28.// 调用接口方法 等待图表结束
29.long evCode;
30.pEvent->WaitForCompletion(INFINITE, &evCode);
31.
32.
33.// 释放调用的对象及其接口
34.pMediaControl->Release();
35.pEvent->Release();
36.pGraph->Release();
37.
38.
39.// 释放COM库所使用的资源
40.CoUninitialize();
41.
42.
43.}