I am trying to connect to a filtergraph via the Running Object Table and add a Filter.
I can stop and start the graph, but that is about it. I get an error. I can do this with the original GraphEdit, but GraphEditPlus and GraphEditNext and GraphStudioNext cannot. Error is VFW_E_NOT_IN_GRAPH.
CLSCTX_INPROC_SERVER I feel is wrong, but CLSCTX_INPROC_HANDLER doesn't work. I did use IDA on GraphEdit.exe and noticed they use CoCreateInstance with integer 23 which, doesn't seem to exist. CLSCTX_INPROC_SERVER is integer 1.
Here is some sample code? I tried the same thing with DirectShowLib with C# and I get the same error with both.
CoInitializeEx(nullptr, COINIT_MULTITHREADED); //MTA
CComPtr<IRunningObjectTable> pROT;
if (FAILED(GetRunningObjectTable(0, & pROT)))
return 1;
CComPtr<IEnumMoniker> pEM;
if (FAILED(pROT -> EnumRunning( & pEM)))
return 1;
CComPtr<IBindCtx> pBindCtx;
CreateBindCtx(0, & pBindCtx);
for (CComPtr<IMoniker> pMoniker; S_OK == pEM->Next(1, & pMoniker, NULL); pMoniker = NULL) {
LPOLESTR pDispName = NULL;
if (FAILED(pMoniker->GetDisplayName(pBindCtx, NULL, & pDispName)))
continue;
CStringW strw(pDispName);
CComPtr<IMalloc> pMalloc;
if (FAILED(CoGetMalloc(1, & pMalloc)))
continue;
pMalloc->Free(pDispName);
if (strw.Find(L"!FilterGraph") != -1) {
CComPtr<IUnknown> pUnk;
if (S_OK != pROT->GetObject(pMoniker, & pUnk))
continue;
CComQIPtr<IFilterGraph2> pFG = pUnk;
if (!pFG)
continue;
CComQIPtr<IMediaControl> pMC;
OAFilterState fs;
pMC = pFG;
pMC->Pause();
CComQIPtr<IBaseFilter> pSmartTee;
hr = CoCreateInstance(CLSID_SmartTee, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void **>(&pSmartTee));
if (SUCCEEDED(hr)) {
pFG->AddFilter(pSmartTee, L "Smart Tee");
}
pFG.Detach();
pFG.Release();
pROT.Detach();
break;
}
}