Where is a header for Microsoft::UI namespace to use in a C++/WinRT project?

17 hours ago 3
ARTICLE AD BOX

I want to compile and test the following code, I found on MSDN:

bool SetupBackdrop(winrt::Microsoft::UI::WindowId windowId, winrt::Windows::UI::Composition::CompositionTarget compositionTarget) { winrt::Microsoft::UI::Composition::SystemBackdrops::DesktopAcrylicController desktopAcrylicController = winrt::DesktopAcrylicController(); return desktopAcrylicController.SetTarget(windowId, compositionTarget); }

I created a new C++/WinRT project in VS 2022. It has a lot of WinRT-related headers in pch.h:

#include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.Collections.h> #include <winrt/Windows.System.h> #include <winrt/Windows.UI.Xaml.h> #include <winrt/Windows.UI.Xaml.Controls.h> #include <winrt/Windows.UI.Xaml.Hosting.h> #include <winrt/Windows.UI.Xaml.Media.h> #include <Windows.UI.Xaml.Hosting.DesktopWindowXamlSource.h>

The project was built with no issues. So far so good. But when I tried to find the corresponding header for winrt::Microsoft::UI::WindowId, I just could not.

I guess, the following instructions don't cover my case: https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/consume-apis#cwinrt-projection-headers. I mean, when I tried #include <winrt/Microsoft.UI.h>, the file was not found.

How do I fix this? Should I install something from nuget?

I saw some mentions of midl.exe. Is it now like it was back in COM days with generating headers from IDL? If so, what .idl file should I compile? And is there an equivalent of #import directive, which was a better approach for COM?

Also, I tried this answer:

#include <wil/cppwinrt.h> #include <wil/cppwinrt_helpers.h>

(have no idea what wil is), but to no avail.

UPD

The easiest way to fix this was to create a new WinUI C++ project in Visual Studio (instead of C++/WinRT).

But I'm not sure, what's the difference. Is it one of those nuget packages? Or packages.config?

UPD 2

Unfortunately, the WinUI project requires packaging, it cannot be just run until I make it self-contained. It's too much for a single call of winrt::Microsoft::UI::Composition::SystemBackdrops::DesktopAcrylicController::SetTarget() I need for an existing Win32 window.

Read Entire Article