DirectShow 的简单例子



// testDirectShow.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include

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

int _tmain(int argc, _TCHAR* argv[])
{
    IGraphBuilder * pGraph = NULL;
    IMediaControl * pControl = NULL;
    IMediaEvent *pEvent = NULL;

    HRESULT hr = CoInitialize(NULL);
    if(FAILED(hr))
    {
        printf("Can't not initialize com \n");
        return 0;
    }

    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) & pGraph);
    if(FAILED(hr))
    {
         printf("Can't not create graphic builder com \n");
        return 0;
    }

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **) & pControl);
    if(FAILED(hr))
    {
         printf("Can't not query media control interface \n");
        return 0;
    }

    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **) &pEvent);
    if(FAILED(hr))
    {
         printf("Can't not query media event interface \n");
        return 0;
    }


    hr = pGraph->RenderFile(argv[1], NULL);
    if(SUCCEEDED(hr))
    {
        hr = pControl->Run();
       
        if(SUCCEEDED(hr))
        {
            long retCode;
            pEvent->WaitForCompletion(INFINITE, &retCode);
           
        }    

    }

    pEvent->Release();
    pControl->Release();
    pGraph->Release();

    CoUninitialize();
 return 0;
}


你可能感兴趣的:(自斧之楥)