المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : BindToObject fails - DirectShow remote graph access



C++ Programming
04-11-2013, 10:30 PM
TRACE("\nHRESULT CDS::C_AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)");
IMoniker * pMoniker;
IRunningObjectTable *pROT;

IEnumMoniker *pMonikersTable;
IMoniker *pCurrentMoniker;
int iTestCount = 0;

WCHAR wsz[128] = L"Video" ; // MN used to retrive
HRESULT hr;
if (!pUnkGraph || !pdwRegister)
{
TRACE("\n!pUnkGraph || !pdwRegister");
return E_POINTER;
}
TRACE("\nGetRunningObjectTable ");
if (FAILED(GetRunningObjectTable(0, &pROT)))
{
TRACE("\nGetRunningObjectTable(0, &pROT)");
return E_FAIL;
}
// test enumerate before usage
pROT->EnumRunning(&pMonikersTable);
hr = pMonikersTable->Reset();
if(FAILED(hr))
{
TRACE("\nFailed pROT->Register(.. ");
}
while(pMonikersTable->Next(1, &pCurrentMoniker, NULL) == S_OK)
{
iTestCount++;
TRACE("\n");
}
/*
hr = StringCchPrintfW(wsz, NUMELMS(wsz), L"FilterGraph %08x pid %08x\0", (DWORD_PTR)pUnkGraph,
GetCurrentProcessId());
*/
TRACE("\nCreateItemMoniker using name ");
hr = CreateItemMoniker(L"!", wsz, &pMoniker);
if (SUCCEEDED(hr)) {
TRACE("\nRegister moniker ");
// Use the ROTFLAGS_REGISTRATIONKEEPSALIVE to ensure a strong reference
// to the object. Using this flag will cause the object to remain
// registered until it is explicitly revoked with the Revoke() method.
//
// Not using this flag means that if GraphEdit remotely connects
// to this graph and then GraphEdit exits, this object registration
// will be deleted, causing future attempts by GraphEdit to fail until
// this application is restarted or until the graph is registered again.
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph,
pMoniker, pdwRegister);
if(FAILED(hr))
{
TRACE("\nFailed pROT->Register(.. ");
}
pMoniker->Release();
}
pROT->Release();


THIS IS A DIFFERENT "FUNCTION"

HRESULT hr;
TRACE("\nBind to control "); // Get a BindCtx.
IBindCtx *pbc;
hr = CreateBindCtx(0, &pbc);
if(FAILED(hr))
{
TRACE("\nCreateBindCtx()", hr);
return false;
}

TRACE("\nGet running-object table.");
IRunningObjectTable *prot;
hr = pbc->GetRunningObjectTable(&prot);
if(FAILED(hr))
{
TRACE("\nCreateBindCtx()", hr);
prot->Release();
return false;
}
TRACE("\nGet enumeration interface.");
IEnumMoniker *pem; // enumerated moniker
hr = prot->EnumRunning(&pem);
if(FAILED(hr))
{
TRACE("\nCreateBindCtx()", hr);
prot->Release();
pbc->Release();
return false;
}
// Start at the beginning.
pem->Reset();
// Churn through enumeration.
ULONG fetched; // actuall number of items retrived , could ve set to NULL
IMoniker *pmon;
int n = 0;
while(pem->Next(1, &pmon, &fetched) == S_OK)
{
TRACE("\nGet moniker for %s Graph name ", strName); // Get DisplayName.
LPOLESTR pName;
pmon->GetDisplayName(pbc, NULL, &pName);
// Convert it to ASCII.
char szName[512];
WideCharToMultiByte(CP_ACP, 0, pName, -1, szName, 512, NULL,
NULL);
TRACE("\nCompare with Moniker name %s",szName); // Compare it against the name we got in SetHostNames().
if(strName.CompareNoCase(szName) /* "!Video")*/ == 0 )
//if(!strcmp(szName, "!Video")) //MN for now
{
TRACE("\nBind to this ROT entry moniker named %s",strName);
/*
IDispatch *pDisp;
hr = pmon->BindToObject(pbc, NULL, IID_IDispatch, (void
**)&pDisp);
*/
IUnknown *pUnkGraph;
hr = pmon->BindToObject(pbc, NULL, IID_IUnknown, (void
**)&pUnkGraph);


if(!FAILED(hr))
{
TRACE("\nBound to object ");
// Remember IDispatch.
// m_pDocDisp = pDisp;
// Notice...
//sprintf(buf, "Document IDispatch = %08lx",
//m_pDocDisp);
//DoMsg(buf);
break;
}
else
{
AfxMessageBox("Failed IUnknown *pUnkGraph;");
TRACE("\nFailed BindToObject() %i ", hr);
}
}
// Release interfaces.
pmon->Release();
// Break out if we obtained the IDispatch successfully.
// if(m_pDocDisp != NULL) break;

}
// Release interfaces.
pem->Release();
prot->Release();
pbc->Release();


PS I cannot do "preview" getting "specified module cannot be found".
So if tthis post is too messy, sorry about that