GraphEdit can load a filter graph created by an external process. With this feature, you can see exactly what filter graph your application builds, with only a minimal amount of additional code in your application.
The application must register the filter graph instance in the Running Object Table (ROT). The ROT is a globally accessible look-up table that keeps track of running objects. For information about how your application can add its filter graph to the ROT, see the topic Loading a Graph From an External Process in the Microsoft DirectShow documentation.
To use this feature, perform the following steps:
Compile your application with code that adds a ROT entry for the filter graph.
Run GraphEdit.
Run your application.
In the File menu, click Connect to Remote Graph....
In the Select a remote filter graph to view... dialog box, select the process ident
ifier (pid) of the second application.
Click OK.
To refresh the list of process identifiers, click Refresh in the dialog box.
注意這只能在2000和XP下能用。
下面是將你在應(yīng)用程序中的Filter Graph添加到ROT的代碼,
HRESULT AuGraph::AddToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
HRESULT hr = NOERROR;
IMoniker * pMoniker = NULL;
IRunningObjectTable * pROT = NULL;
if(FAILED(GetRunningObjectTable(0,&pROT)))
{
return E_FAIL;
}
WCHAR wsz[256];
::memset(wsz,0,256);
//wsprintfW(wsz,L"PID: %08x IGraphFilter = %08x",(DWORD_PTR)pUnkGraph,GetCurrentProcessId());
hr = StringCchPrintfW(wsz, NUMELMS(wsz), L"FilterGraph %08x pid %08x",
(DWORD_PTR)pUnkGraph,GetCurrentProcessId());
hr = CreateItemMoniker(L"!",wsz,&pMoniker);
if(SUCCEEDED(hr))
{
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,pUnkGraph,pMoniker,pdwRegister);
pMoniker->Release();
}
pROT->Release();
return hr;
}
下面是在我們使用了之后要除掉它的代碼:
void AuGraph::RemoveFromRot(DWORD pdwRegister)
{
IRunningObjectTable *pROT = NULL;
if(SUCCEEDED(GetRunningObjectTable(0,&pROT)))
{
pROT->Revoke(pdwRegister);
pROT->Release();
}
}
在我們整個(gè)應(yīng)用程序中的代碼結(jié)構(gòu)如下:
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,(void **)&m_pGB);
if(FAILED(hr))
{
return hr;
}
#ifdef _DEBUG
hr = AddToRot(m_pGB,&dwRegister);
#endif
.............應(yīng)用程序
#ifdef _DEBUG
RemoveFromRot(dwRegister);
#endif
if(m_pGB)
m_pGB = NULL;
The application must register the filter graph instance in the Running Object Table (ROT). The ROT is a globally accessible look-up table that keeps track of running objects. For information about how your application can add its filter graph to the ROT, see the topic Loading a Graph From an External Process in the Microsoft DirectShow documentation.
To use this feature, perform the following steps:
Compile your application with code that adds a ROT entry for the filter graph.
Run GraphEdit.
Run your application.
In the File menu, click Connect to Remote Graph....
In the Select a remote filter graph to view... dialog box, select the process ident
ifier (pid) of the second application.
Click OK.
To refresh the list of process identifiers, click Refresh in the dialog box.
注意這只能在2000和XP下能用。
下面是將你在應(yīng)用程序中的Filter Graph添加到ROT的代碼,
HRESULT AuGraph::AddToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
HRESULT hr = NOERROR;
IMoniker * pMoniker = NULL;
IRunningObjectTable * pROT = NULL;
if(FAILED(GetRunningObjectTable(0,&pROT)))
{
return E_FAIL;
}
WCHAR wsz[256];
::memset(wsz,0,256);
//wsprintfW(wsz,L"PID: %08x IGraphFilter = %08x",(DWORD_PTR)pUnkGraph,GetCurrentProcessId());
hr = StringCchPrintfW(wsz, NUMELMS(wsz), L"FilterGraph %08x pid %08x",
(DWORD_PTR)pUnkGraph,GetCurrentProcessId());
hr = CreateItemMoniker(L"!",wsz,&pMoniker);
if(SUCCEEDED(hr))
{
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,pUnkGraph,pMoniker,pdwRegister);
pMoniker->Release();
}
pROT->Release();
return hr;
}
下面是在我們使用了之后要除掉它的代碼:
void AuGraph::RemoveFromRot(DWORD pdwRegister)
{
IRunningObjectTable *pROT = NULL;
if(SUCCEEDED(GetRunningObjectTable(0,&pROT)))
{
pROT->Revoke(pdwRegister);
pROT->Release();
}
}
在我們整個(gè)應(yīng)用程序中的代碼結(jié)構(gòu)如下:
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,(void **)&m_pGB);
if(FAILED(hr))
{
return hr;
}
#ifdef _DEBUG
hr = AddToRot(m_pGB,&dwRegister);
#endif
.............應(yīng)用程序
#ifdef _DEBUG
RemoveFromRot(dwRegister);
#endif
if(m_pGB)
m_pGB = NULL;