Add to Running Object Table

Started by Jon Eskdale, July 04, 2014, 05:07:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jon Eskdale

There is a sample of reading the Running Object Table in COM examples section

What I would like to do is add an entry to the ROT so that I can attach the Graphedt to a running Graph.  MSDN uses the function AddToRot() but I can't find anyway of doing this in PowerBasic.  Any pointers or Sample would be greatly appreciated.

Thanks Jon

José Roca

AddToRot is a method of the C++ CRot class:


  // Rot.cpp listing

HRESULT CRot::AddToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
    IMoniker * pMoniker = NULL;
    IRunningObjectTable *pROT = NULL;

    if (FAILED(GetRunningObjectTable(0, &pROT)))
    {
        return E_FAIL;
    }
   
    const size_t STRING_LENGTH = 256;

    WCHAR wsz[STRING_LENGTH];
    StringCchPrintfW(wsz, STRING_LENGTH, 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;



Jon Eskdale

Thanks so much Jose - sorry for delay in replying - have been on duty looking after the Parents in law - now back to the PC
Jon

Jon Eskdale

For anyone searching this in the future this is what I ended up with - It seems to work but I'm not an expert so be free to comment and point out any errors.


FUNCTION AddToROT(pUnkGraph as IUnknown, byref pdwRegister as dword) as long

   LOCAL hr AS LONG
   LOCAL pbc AS IBindCtx                  'Pointer to Bind Context Object
   LOCAL pRot AS IRunningObjectTable
   LOCAL pMoniker AS IMoniker
   LOCAL wszItem as wstringz * 50
   
   
   wszItem = "FilterGraph " & HEX$(objptr(pUnkGraph),8) & " pid " & HEX$(GetCurrentProcessId(),8)

   FUNCTION = %E_FAIL
   
   ' // Get a pointer to a bind context
   hr = CreateBindCtx(0, pbc)
   IF hr <> %S_OK THEN EXIT FUNCTION

   ' // Get a reference to the Running Object Table (ROT)
   hr = pbc.GetRunningObjectTable(pRot)
   IF hr <> %S_OK THEN EXIT FUNCTION
   
   hr = CreateItemMoniker("!", wszItem, pMoniker)
   hr = pRot.Register(%ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, pMoniker, pdwRegister)

   pbc = NOTHING
   pRot = NOTHING
   FUNCTION = hr
END FUNCTION

SUB RemoveFromROT(BYREF pdwRegister as DWORD)
   LOCAL hr AS LONG
   LOCAL pbc AS IBindCtx                  'Pointer to Bind Context Object
   LOCAL pRot AS IRunningObjectTable

   ' // Get a pointer to a bind context
   hr = CreateBindCtx(0, pbc)
   IF hr <> %S_OK THEN EXIT SUB

   ' // Get a reference to the Running Object Table (ROT)
   hr = pbc.GetRunningObjectTable(pRot)
   IF hr <> %S_OK THEN EXIT SUB
   
   hr = pRot.Revoke(pdwRegister)
   
   pbc = NOTHING
   pRot = NOTHING   
END SUB


Sample calls are


hr = AddtoROT(pIGraphBuilder, dwRegister)

RemoveFromRot(dwRegister)