DEV Community

Pastukhov Aleksey
Pastukhov Aleksey

Posted on

Part 3: putting it al l together

#include <windows.h>
#include <objbase.h>
#include <stdio.h>

int main(int argc, char * argv[]) {
    CoInitializeEx(0, COINIT_APARTMENTTHREADED);

    IRunningObjectTable *pROT  = 0;
    IEnumMoniker        *pEnum = 0;
    IBindCtx            *pCtx  = 0;
    IMoniker *pMon   = 0;
    ULONG     fetched = 0;

    GetRunningObjectTable(0, &pROT);
    pROT->lpVtbl->EnumRunning(pROT, &pEnum);
    CreateBindCtx(0, &pCtx);

    while (pEnum->lpVtbl->Next(pEnum, 1, &pMon, &fetched) == S_OK) {
        LPOLESTR name = NULL;
        if (SUCCEEDED(pMon->lpVtbl->GetDisplayName(pMon, pCtx, 0, &name))) {
            wprintf(L"%s\n", name);
            CoTaskMemFree(name);
        }
        pMon->lpVtbl->Release(pMon);
    }

    pCtx->lpVtbl->Release(pCtx);
    pEnum->lpVtbl->Release(pEnum);
    pROT->lpVtbl->Release(pROT);
    CoUninitialize();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Compile with:

cl rot_enum.c ole32.lib
Enter fullscreen mode Exit fullscreen mode

What you'll actually see - on my comp the output looks like:
Image description: Running Object Table as is

Top comments (0)