【问题标题】:Exception thrown when attemping to close DesktopWindowXamlSource尝试关闭 DesktopWindowXamlSource 时引发异常
【发布时间】:2020-01-11 07:13:39
【问题描述】:

我正在为我的 Win32 C++ 应用程序使用 UWP Xaml 托管 API。我有以下代码:

        winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager XamlManager = winrt::Windows::UI::Xaml::Hosting::
        WindowsXamlManager::InitializeForCurrentThread();
        winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource XamlSource;

当我完成 UWP 内容后,我正在调用

    XamlSource.Close();
    XamlManager.Close();

但调试器的输出窗口表明正在抛出异常: windows\advcore\winrt\iwindow\corewindow\desktop\desktopwindowcontentbridge.cpp(499)\Windows.UI.dll!00007FFD91CD860F: (caller: 00007FFD91CD7704) ReturnHr(1) tid(7168) 8007139F The group or resource is not in the correct state to perform the requested operation.

我做错了什么?

【问题讨论】:

  • 您似乎在使用 C++/WinRT。如果是这种情况,则无需手动 Close 资源。只需让智能指针超出范围,并让析构函数进行清理。除非你在做一些有趣的事情,否则这会建立正确的破坏顺序。不过,需要minimal reproducible example 才能获得明确的答案。

标签: c++ xaml winapi uwp xaml-islands


【解决方案1】:

您是否对您的应用程序进行了清单化?

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">unaware</dpiAwareness>
    </windowsSettings>
  </application>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <maxversiontested Id="10.0.18362.0"/>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
    </application>
  </compatibility>
</assembly>

来自my article

【讨论】:

  • 是的,但调试窗口输出中显示了相同的消息。
猜你喜欢
  • 2010-10-21
  • 1970-01-01
  • 1970-01-01
  • 2014-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
相关资源
最近更新 更多