Error when asking Running Object Table (ROT) out of main thread

0

I have this method to test if I successfully get ROT:

void func()
{
    IRunningObjectTable *rot;
    qDebug() << GetRunningObjectTable(0, &rot);
}

Everything's fine from main thread but not in a separate one:

func(); // qDebug prints S_OK (0)
QFuture<void> future = QtConcurrent::run(func); // qDebug prints E_UNEXPECTED (0x8000FFFF)

Compiling with MinGW 5.3.0 32bits.

I don't get why would it be different from the main thread than an other.

Help would be appreciated.

c++
qt
mingw
qthread
ole
asked on Stack Overflow Nov 28, 2019 by G. Lusson

1 Answer

1

Because your thread function didn't invoke CoInitialize or CoInitializeEx before invoking GetRunningObjectTable.

This would likely work from a thread

void func_in_thread()
{
    CoInitializeEx(nullptr,COINIT_MULTITHREADED);

    IRunningObjectTable *rot = nullptr;
    qDebug() << GetRunningObjectTable(0, &rot);

    CoUninitialize();
}
answered on Stack Overflow Nov 28, 2019 by selbie

User contributions licensed under CC BY-SA 3.0