0

I am using the UWP Xaml hosting API for my Win32 C++ App. I have the following code:

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

When I am finished with the UWP Content, I am calling

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

But the output window from the debugger indicates an exception is being thrown: 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.

What am I doing wrong?

Arush Agarampur
  • 1,340
  • 7
  • 20
  • You seem to be using C++/WinRT. If that is the case, there's no need to manually `Close` resources. Just let the smart pointers fall out of scope, and have the destructor do the cleanup. Unless you're doing something funny this establishes the correct order of destruction. Still, a [mcve] is required to get a definitive answer. – IInspectable Jan 11 '20 at 07:25

1 Answers1

2

Did you manifest your application?

<?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>

From my article.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78