2 years ago

#37433

test-img

ackh

Cannot compile WinUI 3.0 app that references a custom Windows Runtime component

I have a Visual Studio 2019 solution that contains two project.

The first project has been created using the "Windows Runtime Component (WinUI 3) Visual Studio template (library project). It generates a dll and associated winmd file that contains a DirectX-based Windows Runtime component to be used in the user interface of a WinUI 3.0 app.

The second project has been created using the "Blank App, Packaged (WinUI 3 in Desktop)" Visual Studio template. It generates a Win32 app that utilizes WinUI 3.0 as the UI framework and consumes the output of the first project.

That second project references the first project via Visual Studio / MSBuild project reference.

The first project defines the component via MIDL as follows:

namespace My.Company.Name.DirectX
{
  runtimeclass CustomControl : Microsoft.UI.Xaml.Controls.SwapChainPanel
  {
    CustomControl();
    // All interface methods and properties
  }
}

The header that gets generated form this looks as follows:

namespace winrt::My::Company::Name::DirectX::implementation
{
  struct CustomControl : CustomControlT<CustomControl>
  {
  public:
    CustomControl();
    ~CustomControl();
    // // All interface methods and properties
  };
}

namespace winrt::My::Company::Name::DirectX::factory_implementation
{
  struct CustomControl : CustomControlT<CustomControl, implementation::CustomControl>
  {
  };
}

I then attempt to use that component within a Microsoft.UI.Xaml.Controls.Page XAML file as follows:

<Page
  x:Class="My.Company.Name.App.CustomControlPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:My.Company.Name.App"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:Controls="using:My.Company.Name.DirectX"
  mc:Ignorable="d">

  <Controls:CustomControl/>

</Page>

However, if I compile the entire code I get the following error messages:

My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(145): message : see reference to class template instantiation 'winrt::My::Company::Name::App::implementation::CustomControlPageT<D,I...>' being compiled (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,66): error C3646: 'CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,76): error C2059: syntax error: '(' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(30,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,62): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,71): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,1): error C2061: syntax error: identifier 'CustomControl' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,66): error C3646: '_CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,77): error C2059: syntax error: '{' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,13): error C3861: '_CustomControl': identifier not found (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,27): error C3861: 'value': identifier not found (compiling source file Page\CustomControlPage.cpp)

Somehow, my CustomControl is not recognized when compiling the source code that is generated for the XAML file that references it. I don't understand what the problem is. In theory, all I that is required to use that component is the winmd file because it should describe that component.

Can someone tell me why I'm getting these errors?

Edit:

I have attempted to reproduce the problem and the resulting Git repository is available here

winrt-xaml

c++-winrt

winui-3

winrt-component

cppwinrt

0 Answers

Your Answer

Accepted video resources