从主线程中询问 运行 对象 Table (ROT) 时出错
Error when asking Running Object Table (ROT) out of main thread
我有这个方法可以测试我是否成功获得ROT:
void func()
{
IRunningObjectTable *rot;
qDebug() << GetRunningObjectTable(0, &rot);
}
主线程中的一切都很好,但在单独的线程中却不行:
func(); // qDebug prints S_OK (0)
QFuture<void> future = QtConcurrent::run(func); // qDebug prints E_UNEXPECTED (0x8000FFFF)
使用 MinGW 5.3.0 32 位编译。
我不明白为什么它与主线程不同。
不胜感激。
因为您的线程函数在调用 GetRunningObjectTable 之前没有调用 CoInitialize or CoInitializeEx。
这可能适用于线程
void func_in_thread()
{
CoInitializeEx(nullptr,COINIT_MULTITHREADED);
IRunningObjectTable *rot = nullptr;
qDebug() << GetRunningObjectTable(0, &rot);
CoUninitialize();
}
我有这个方法可以测试我是否成功获得ROT:
void func()
{
IRunningObjectTable *rot;
qDebug() << GetRunningObjectTable(0, &rot);
}
主线程中的一切都很好,但在单独的线程中却不行:
func(); // qDebug prints S_OK (0)
QFuture<void> future = QtConcurrent::run(func); // qDebug prints E_UNEXPECTED (0x8000FFFF)
使用 MinGW 5.3.0 32 位编译。
我不明白为什么它与主线程不同。
不胜感激。
因为您的线程函数在调用 GetRunningObjectTable 之前没有调用 CoInitialize or CoInitializeEx。
这可能适用于线程
void func_in_thread()
{
CoInitializeEx(nullptr,COINIT_MULTITHREADED);
IRunningObjectTable *rot = nullptr;
qDebug() << GetRunningObjectTable(0, &rot);
CoUninitialize();
}