调试DirectShow程序的时候,利GraphEdit查看自已程序中的Graph

时间:2022-09-17 23:20:24

摘自DirectX帮助文档中的两个函数:

1.下面的这个函数是将我们的IGraphBuilder接口添加到GraphEdit中去.

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;
}

2.下面的这个函数是从GraphEdit中移除我们的IGraphBuilder.

void RemoveFromRot(DWORD pdwRegister)
{
     IRunningObjectTable
*pROT;
    
if (SUCCEEDED(GetRunningObjectTable(0, &pROT))) {
         pROT
->Revoke(pdwRegister);
         pROT
->Release();
     }
}

3.以上两个函数在程序的使用方法.

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();

4.打开GraphEdit程序后,点击File菜单->Connect to Remote Graph或Ctrl+G出现一个选窗口点击确定就可以看到你程序中的Graph了!