Author Topic: Add to Running Object Table  (Read 5844 times)

0 Members and 1 Guest are viewing this topic.

Offline Jon Eskdale

  • Newbie
  • *
  • Posts: 35
  • User-Rate: +2/-0
Add to Running Object Table
« on: July 04, 2014, 05:07:15 PM »
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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2530
  • User-Rate: +209/-0
  • Gender: Male
Re: Add to Running Object Table
« Reply #1 on: July 05, 2014, 12:42:02 AM »
AddToRot is a method of the C++ CRot class:

Code: [Select]
  // 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;


Offline Jon Eskdale

  • Newbie
  • *
  • Posts: 35
  • User-Rate: +2/-0
Re: Add to Running Object Table
« Reply #2 on: July 08, 2014, 05:54:18 PM »
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

Offline Jon Eskdale

  • Newbie
  • *
  • Posts: 35
  • User-Rate: +2/-0
Re: Add to Running Object Table
« Reply #3 on: July 10, 2014, 07:01:37 PM »
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.

Code: [Select]
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

Code: [Select]
hr = AddtoROT(pIGraphBuilder, dwRegister)

RemoveFromRot(dwRegister)