Alex Fedotov.com 

Requirements

Development Environment Requirements

Microsoft Visual C++ 6.0

Run-Time Requirements

Microsoft Windows NT 4.0 or later
Microsoft Windows 95 or later

<< Hide left pane Leave feedback

Enumerating ROT Sample

The Running Object Table (ROT) is a globally accessible table that keeps track of all COM objects in the running state that can be identified by a moniker. When a client tries to bind a moniker to an object, the moniker checks the ROT to see if the object is already running; this allows the moniker to bind to the current instance instead of loading a new one.

This sample demonstrates how to enumerate all objects registered in the ROT. I do remember that previous versions of Platform SDK offered an utility called ROTView that allowed to examine the ROT. Recently, I needed to check if a particular program registers itself in the ROT therefore I tried looking for ROTView on MSDN and on the Internet. I was suprised that only a few traces were found and none of them offered files to download.

Thus I decided to create this utility and make it a sample available from my Web site. Below is a part of the sample program source code that enumerates all currently registered objects and prints out display names of the corresponding monikers.

int _tmain(
    int argc, 
    _TCHAR * argv[]
    )
{
    HRESULT hRes;
    
    hRes = OleInitialize(NULL);
    if (FAILED(hRes))
    {
        _tprintf("OleInitialize failed (0x%08X)\n", hRes);
        return -1;
    }

    IRunningObjectTable * pROT = NULL;
    IEnumMoniker * pEnum = NULL;
    IMoniker * pMoniker = NULL;
    IBindCtx * pBindCtx = NULL;
    PWSTR pszName = NULL;
    ULONG cElt;

    for (;;)
    {
        // get interface pointer of the running object table
        hRes = GetRunningObjectTable(NULL, &pROT);
        if (FAILED(hRes))
        {
            _tprintf("GetRunningObjectTable failed (0x%08X)\n", hRes);
            break;
        }

        // create binding context object
        hRes = CreateBindCtx(0, &pBindCtx);
        if (FAILED(hRes))
        {
            _tprintf("CreateBindCtx failed (0x%08X)\n", hRes);
            break;
        }

        // enumerate running objects
        hRes = pROT->EnumRunning(&pEnum);
        if (FAILED(hRes))
        {
            _tprintf("IRunningObjectTable::EnumRunning failed (0x%08X)\n",
                     hRes);
            break;
        }

        // go through all monikers in the table and display moniker name
        while (pEnum->Next(1, &pMoniker, &cElt) == S_OK)
        {
            hRes = pMoniker->GetDisplayName(pBindCtx, NULL, &pszName);
            if (FAILED(hRes))
            {
                _tprintf("IMoniker::GetDisplayName failed (0x%08X)\n", hRes);
                break;
            }

            _tprintf("%ls\n", pszName);

            CoTaskMemFree(pszName);
            pMoniker->Release();

            pszName = NULL;
            pMoniker = NULL;
        }

        break;
    }

    if (pszName != NULL)
        CoTaskMemFree(pszName);
    if (pMoniker != NULL)
        pMoniker->Release();
    if (pEnum != NULL)
        pEnum->Release();
    if (pBindCtx != NULL)
        pBindCtx->Release();
    if (pROT != NULL)
        pROT->Release();

    OleUninitialize();
    return 0;
}

Leave your comment

From:
Subject:
Comment:
 
 
Best viewed with Microsoft Internet Explorer 4.0+Send feedback to: me@alexfedotov.com
Last modified on Fri, Feb 10 2006

HotLog