This sample demonstrates how older C++/CX Windows Runtime components can still be consumed from modern WinUI 3 applications written in either C++/WinRT or C#. It combines a native component, a generated CsWinRT projection, and two app front ends so you can compare interop patterns across languages and projection layers.
WinUI3_cppcx
|-- WinRt_cppcx/ C++/CX Windows Runtime component
|-- WinUI3App_cpp/ C++/WinRT consumer app
|-- WinUI3App_cs/ C# WinUI 3 consumer app
`-- WinRt_cppcx_projection/ CsWinRT projection for C# consumption
WinRt_cppcxcontains the component authored with C++/CX.WinUI3App_cppshows how a C++/WinRT WinUI 3 app can consume that component.WinUI3App_csshows the C# side of the same story through the generated projection layer.WinRt_cppcx_projectionprovides the CsWinRT projection that makes the C++/CX component easy to reference from managed code.- The solution is a practical reference when migrating code incrementally instead of rewriting every WinRT component at once.
- The C# app also demonstrates AppWindow-based windowing APIs alongside the interop sample.
- Because both consumers are in the same solution, it is easy to compare native and managed usage patterns side-by-side.
- Open
WinUI3_cppcx.slnin Visual Studio 2022. - Restore dependencies and ensure C++ desktop, .NET desktop, and Windows App SDK workloads are installed.
- Build the solution for a supported target such as
x64orARM64. - Ensure the component and projection build before launching the consumer apps.
- Run either
WinUI3App_cpporWinUI3App_csto inspect how each app consumes the shared runtime component.
