![2011061810504056.jpg](https://i-blog.csdnimg.cn/blog_migrate/4e482f84d03c9b0489c9a102ff3f6379.jpeg)
![2011061810510123.jpg](https://i-blog.csdnimg.cn/blog_migrate/c51af927117723fb0bf6295bf858a91c.jpeg)
![2011061810511519.jpg](https://i-blog.csdnimg.cn/blog_migrate/037ae3640bffcb760f443cb4b0ef1e2b.jpeg)
#include "stdafx.h"
#include <DShow.h>
int _tmain(int argc, _TCHAR* argv[])
{
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 1;
}
// 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 1;
}
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"E:\\red_sun.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();
return 0;
}
- 没问题的话即可在桌面看到一播放窗口。
- 参考:DirectShow帮助文档