C++/WinRTagile_ref应该允许以敏捷的方式使用非敏捷对象。但是,我发现这至少在CoreWindow实例中失败了。
作为一个简短的例子:
void Run()
{
auto window{ CoreWindow::GetForCurrentThread() };
window.Activate();
auto agile_wnd{ make_agile(window) };
ThreadPool::RunAsync([=](const auto&) {
auto other_wnd{ agile_wnd.get() };
other_wnd.SetPointerCapture();
});
auto dispatcher{ window.Dispatcher() };
dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}
Run()在 UI 线程上调用,然后尝试创建一个敏捷引用,然后使用它CoreWindow从线程池中调用。但是,这失败了,"The application called an interface that was marshaled for a different thread."因为agile_ref使用RoGetAgileReference内部编组对象,并且创建引用然后解组它的调用都成功了,在我看来,这似乎CoreWindow只是拒绝被编组。
当然,除非这是按预期工作并且RoGetAgileReference调用默默地无法编组CoreWindow.
那么是什么导致SetPointerCapture调用失败,即使使用agile_ref?