在翻阅DirectX 9.0 SDK帮助文档的时候,看到一个Loading a Graph From an External Process的主题,仔细的阅读了下芳知它可以利GraphEdit来查看自已程序中正在运行的IGraphBuilder中的图形,可想而知在调试一个DirectShow程序的时候利GraphEdit来查看图形是多么直观的一个方法,可以给我们在调试的时候带来很大的方便和优势,废话就少说了,下面来介绍两个函数!
摘自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;
}
{
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();
}
}
{
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();
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了!