Microsoft DirectX 8.1 (C++) |
The following is the complete code for the sample application described in this article.
#include <dshow.h>
#include <qedit.h>
// Preview a timeline.
void PreviewTL(IAMTimeline *pTL, IRenderEngine *pRender)
{
HRESULT hr;
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
// Build the graph.
hr = pRender->SetTimelineObject(pTL);
hr = pRender->ConnectFrontEnd( );
hr = pRender->RenderOutputPins( );
// Run the graph.
hr = pRender->GetFilterGraph(&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pControl->Run();
long evCode;
hr = pEvent->WaitForCompletion(INFINITE, &evCode);
pControl->Stop();
// Clean up.
pEvent->Release();
pControl->Release();
pGraph->Release();
}
void main( void )
{
HRESULT hr;
IAMTimeline *pTL = NULL;
IRenderEngine *pRender = NULL;
IXml2Dex *pXML = NULL;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER,
IID_IAMTimeline, (void**)&pTL);
hr = CoCreateInstance(CLSID_Xml2Dex, NULL, CLSCTX_INPROC_SERVER,
IID_IXml2Dex, (void**)&pXML);
hr = CoCreateInstance(CLSID_RenderEngine, NULL, CLSCTX_INPROC_SERVER,
IID_IRenderEngine, (void**)&pRender);
// Load a project file.
BSTR bstrFile = SysAllocStringLen(OLESTR("C:\\example.xtl"), 15);
hr = pXML->ReadXMLFile(pTL, bstrFile);
SysFreeString(bstrFile);
pXML->Release();
PreviewTL(pTL, pRender);
// Clean up.
pRender->ScrapIt();
pTL->Release();
pRender->Release();
CoUninitialize();
}