<< 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 (;;)
{
hRes = GetRunningObjectTable(NULL, &pROT);
if (FAILED(hRes))
{
_tprintf("GetRunningObjectTable failed (0x%08X)\n", hRes);
break;
}
hRes = CreateBindCtx(0, &pBindCtx);
if (FAILED(hRes))
{
_tprintf("CreateBindCtx failed (0x%08X)\n", hRes);
break;
}
hRes = pROT->EnumRunning(&pEnum);
if (FAILED(hRes))
{
_tprintf("IRunningObjectTable::EnumRunning failed (0x%08X)\n",
hRes);
break;
}
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;
}