Why am I getting these errors, and do I need to include other header files?

CDev-8220 365 Reputation points
2025-05-30T14:26:07.9166667+00:00
/* You can also use project link settings to explicitly link WindowsApp.lib.
Or, you can do it in source code (in pch.h, for example) like this. */
#pragma comment(lib, "windowsapp")
/* To use Windows Runtime (WinRT) APIs in your Win32 app, we use C++/WinRT.
The Windows SDK headers are the Windows Runtime ABI header files */
#include <windows.foundation.h>
#include <windows.ui.composition.interop.h>
/* all it takes to cause winrt::implements to support classic COM interfaces
is to include the unknwn.h header file before you include any C++/WinRT headers
You could do that explicitly, or indirectly by including some other header file
such as ole2.h. One recommended method is to include the wil\cppwinrt.h header
file, which is part of the Windows Implementation Libraries (WIL).
The wil\cppwinrt.h header file not only makes sure that unknwn.h is included
before winrt/base.h, it also sets things up so that C++/WinRT and WIL understand
each other's exceptions and error codes.
You can then as<> for classic COM interfaces, and the example code will compile */
#include <unknwn.h>
//#include <wil\cppwinrt.h>
/* include C++/WinRT headers */
#include <winrt/base.h>
#include "winrt/Windows.Foundation.h"
#include <winrt/Windows.UI.Composition.Desktop.h>
//#include <winrt/Windows.UI.Composition.h>
//#include <winrt/Windows.UI.Core.h>
#include <DispatcherQueue.h>
#include <presentation.h>
#pragma comment(lib, "dcomp.lib")

/* using namespace aliases for the different islands to deal with otherwise
potential namespace collisions between the C++/WinRT projection and the ABI. */
namespace winrt {
	using namespace winrt::Windows::System;
	using namespace winrt::Windows::UI;
	using namespace winrt::Windows::UI::Core;
	using namespace winrt::Windows::UI::Composition;
	using namespace winrt::Windows::UI::Composition::Desktop;
	using namespace winrt::Windows::Foundation;
	using namespace winrt::Windows::Foundation::Numerics;
}
/* ABI types found in the SDK header
Windows::Foundation, and all other Windows namespaces, are
declared by the SDK headers within the ABI namespace */
namespace abi {
	/* SDK Application Binary Interface, or ABI */
	using namespace ABI::Windows::System;
	using namespace ABI::Windows::UI;
	using namespace ABI::Windows::UI::Composition;
	using namespace ABI::Windows::UI::Composition::Desktop;
	using namespace ABI::Windows::Foundation;
	using namespace ABI::Windows::Foundation::Numerics;
}

I'm using HelloComposition example, and getting errors on the code in the AddCompositionElement function.

The first line of code in the function, auto visuals = m_DesktopWindowTarget.Root().as<abi::ContainerVisual>().Children(); returns these errors:

'ABI::Windows::UI::Composition::ContainerVisual': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' 'ABI::Windows::UI::Composition::ContainerVisual': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' 'ABI::Windows::UI::Composition::ContainerVisual': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' 'ABI::Windows::UI::Composition::ContainerVisual': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' 'ABI::Windows::UI::Composition::ContainerVisual': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' use of undefined type 'ABI::Windows::UI::Composition::ContainerVisual' 'void': all return expressions must deduce to the same type: previously it was 'T' use of undefined type 'ABI::Windows::UI::Composition::ContainerVisual' 'void': all return expressions must deduce to the same type: previously it was 'T' use of undefined type 'ABI::Windows::UI::Composition::ContainerVisual' use of undefined type 'ABI::Windows::UI::Composition::ContainerVisual'

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,960 questions
{count} votes

Accepted answer
  1. Darran Rowe 1,986 Reputation points
    2025-05-30T15:35:04.41+00:00

    What are you trying to do here?

    First of all, unless there is any reason to look elsewhere, if you are using C++/WinRT, you should always look in the winrt root namespace first. So winrt::Windows::UI::Composition::ContainerVisual would be what you want.

    Secondly, this is important, the ABI should always be seen as a last resort. If you really need the ABI interface, and you don't in your sample above, then winrt::get_abi is what would be used to extract the ABI pointer. But it is extracted as a void * so understanding how these interfaces works is important.


1 additional answer

Sort by: Most helpful
  1. Castorix31 90,191 Reputation points
    2025-05-30T14:50:07.89+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.