Partager via


Sample DirectShow Playback Program (Compact 2013)

3/26/2014

The following sample code plays a file. This example is a console application, so set the build target accordingly.

Note

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include <streams.h>

void __cdecl main(void)
{
    IGraphBuilder *pGraph;
    IMediaControl *pMediaControl;
    CoInitialize(NULL);
    
    // Create the filter graph manager.
    CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, 
                        IID_IGraphBuilder, (void **)&pGraph);
    pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);

    // Build the graph. (IMPORTANT: Change string to a file on your system.)
    pGraph->RenderFile(L"\\Hello_World.avi", NULL);

    // Run the graph.
    pMediaControl->Run();

    // Block until the user clicks the OK button. 
    // The filter graph runs on a separate thread.
    MessageBox(NULL, "Click me to end playback.", "DirectShow", MB_OK);

    // Clean up.
    pMediaControl->Release();
    pGraph->Release();
    CoUninitialize();
}

See Also

Tasks

DirectShow Samples