http://support.microsoft.com/default.as ... US;Q313844
c++:
代碼: 選擇全部
HRESULT LoadGraphFile(IGraphBuilder *pGraph, const WCHAR* wszName)
{
IStorage *pStorage = 0;
if (S_OK != StgIsStorageFile(wszName))
{
return E_FAIL;
}
HRESULT hr = StgOpenStorage(wszName, 0,
STGM_TRANSACTED | STGM_READ | STGM_SHARE_DENY_WRITE, 0, 0, &pStorage);
if (FAILED(hr))
{
return hr;
}
IPersistStream *pPersistStream = 0;
hr = pGraph->QueryInterface(IID_IPersistStream, reinterpret_cast<void**>(&pPersistStream));
if (SUCCEEDED(hr))
{
IStream *pStream = 0;
pStorage->OpenStream(L"ActiveMovieGraph", 0,
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream);
if(SUCCEEDED(hr))
{
hr = pPersistStream->Load(pStream);
pStream->Release();
}
pPersistStream->Release();
}
pStorage->Release();
return hr;
}
1. The routine to load GRF-file in Delphi:
代碼: 選擇全部
function LoadGraphFile( pGraph : IGraphBuilder; wszName : WideString ) : HRESULT;
var
pStorage : IStorage;
pPersistStream : IPersistStream;
pStream : IStream;
hr : HRESULT;
begin
//
hr := E_FAIL;
pStorage := nil;
pPersistStream := nil;
pStream := nil;
try
hr := StgIsStorageFile( PWideChar( wszName ) );
if hr <> S_OK then Abort;
hr := StgOpenStorage(
PWideChar( wszName ),
nil,
STGM_TRANSACTED or STGM_READ or STGM_SHARE_DENY_WRITE,
0,
0,
pStorage
);
if hr <> S_OK then Abort;
hr := pGraph.QueryInterface(
IID_IPersistStream,
pPersistStream
);
if hr <> S_OK then Abort;
pStorage.OpenStream(
'ActiveMovieGraph',
0,
STGM_READ or STGM_SHARE_EXCLUSIVE,
0,
pStream
);
if hr <> S_OK then Abort;
hr := pPersistStream.Load( pStream );
if hr <> S_OK then Abort;
except
on E : Exception do
ShowMessage( E.Message );
end;
pStorage := nil;
pPersistStream := nil;
pStream := nil;
result := hr;
end;
代碼: 選擇全部
procedure TformPlayWin.OpenMenuClick(Sender: TObject);
var
hr : HRESULT;
Graph : IGraphBuilder;
wsFileName : WideString;
begin
Graph := nil;
try
if OpenDialog.Execute then
begin
if not FilterGraph.Active then FilterGraph.Active := true;
FilterGraph.ClearGraph;
// ...updated
hr := FilterGraph.QueryInterface( IID_IGraphBuilder, Graph );
if hr <> S_OK then raise Exception.Create( DirectX_GetLastError_MessageString( hr ) );
wsFileName := OpenDialog.FileName;
if UpperCase( ExtractFileExt( wsFileName )) = '.GRF'
then hr := LoadGraphFile( Graph, wsFileName )
else hr := Graph.RenderFile( PWideChar( wsFileName ), 0 );
if hr <> S_OK then raise Exception.Create( DirectX_GetLastError_MessageString( hr ) );
VideoWindow.PopupMenu := PopupMenu;
SoundLevel.Position := FilterGraph.Volume;
FilterGraph.Play;
end;
except
on E : Exception do
ShowMessage( E.Message );
end;
Graph := nil;
end;