扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:智慧的鱼 来源:天极开发 2007年10月16日
关键字:
HRESULT AddToRot(IUnknown *pUnkGraph, DWORD *pdwRegister) { IMoniker * pMoniker; IRunningObjectTable *pROT; if (FAILED(GetRunningObjectTable(0, &pROT))) { return E_FAIL; } WCHAR wsz[256]; wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph, GetCurrentProcessId()); HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker); if (SUCCEEDED(hr)) { hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, pMoniker, pdwRegister); pMoniker->Release(); } pROT->Release(); return hr; } |
void RemoveFromRot(DWORD pdwRegister) { IRunningObjectTable *pROT; if (SUCCEEDED(GetRunningObjectTable(0, &pROT))) { pROT->Revoke(pdwRegister); pROT->Release(); } } |
IGraphBuilder *pGraph; DWORD dwRegister; // Create the filter graph manager. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); #ifdef _DEBUG hr = AddToRot(pGraph, &dwRegister); #endif // Rest of the application (not shown). #ifdef _DEBUG RemoveFromRot(dwRegister); #endif pGraph->Release(); |
图8 |
图9 |
HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath) { const WCHAR wszStreamName[] = L"ActiveMovieGraph"; HRESULT hr; IStorage *pStorage = NULL; hr = StgCreateDocfile( wszPath, STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage); if(FAILED(hr)) { return hr; } IStream *pStream; hr = pStorage->CreateStream( wszStreamName, STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream); if (FAILED(hr)) { pStorage->Release(); return hr; } IPersistStream *pPersist = NULL; pGraph->QueryInterface(IID_IPersistStream, (void**)&pPersist); hr = pPersist->Save(pStream, TRUE); pStream->Release(); pPersist->Release(); if (SUCCEEDED(hr)) { hr = pStorage->Commit(STGC_DEFAULT); } pStorage->Release(); return hr; } |
void __cdecl main(void) { HRESULT hr; IGraphBuilder *pGraph; CoInitialize(NULL); // Create the Filter Graph Manager and render a file. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, reinterpret_cast<void**>(&pGraph)); hr = pGraph->RenderFile(L"C:\\Video.avi", NULL); if (SUCCEEDED(hr)) { hr = SaveGraphFile(pGraph, L"C:\\MyGraph.grf"); } pGraph->Release(); CoUninitialize(); } |
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; hr = 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; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者