【发布时间】:2015-08-18 21:07:19
【问题描述】:
我正在尝试从 windows phone 8.1 C++ 运行时组件访问 CoreWindow。组件需要对 CoreWindow 触发的一些事件做出反应。我有以下代码。
IAsyncAction^ MyClass::RegisterCoreWindowVisibilityChanged()
{
return CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler(
[this]
{
auto eventHandler = ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &MyClass::OnCoreWindowVisibilityChanged);
Window::Current->CoreWindow->VisibilityChanged += eventHandler;
}
));
}
当使用该组件的应用程序是通用应用程序,但在 Silverlight 应用程序中失败并出现访问冲突异常时,此方法可以正常工作。
0xC0000005: Access violation reading location 0x00000000.
显然Windows::Current 在 silverlight 应用程序中返回 null。有没有办法让它在 Silverlight 和 Windows 商店应用程序中运行?
【问题讨论】:
-
与问题没有直接关系,但为什么要使用调度程序附加到事件?
-
Windows::Current->CoreWindow 只能从我认为的UI线程访问。
标签: c# c++ silverlight windows-runtime windows-store-apps