Skip to content

UWP: Migrate from C++/CX to C++/WinRT#18558

Merged
LibretroAdmin merged 1 commit intolibretro:masterfrom
SternXD:uwp-winrt
Jan 2, 2026
Merged

UWP: Migrate from C++/CX to C++/WinRT#18558
LibretroAdmin merged 1 commit intolibretro:masterfrom
SternXD:uwp-winrt

Conversation

@SternXD
Copy link
Copy Markdown
Contributor

@SternXD SternXD commented Dec 31, 2025

Description

Migrates the UWP code from C++/CX to C++/WinRT.

C++/CX is a deprecated, non-standard language extension. C++/WinRT is the replacement, giving us better compatibility and support. I have smoke tested this for a few hours with no regressions I could find.

EDIT here's what Microsoft says about it:

C++/WinRT is the recommended alternative to C++/CX. It is a new, standard C++17 language projection for Windows Runtime APIs, available in the latest Windows SDK from version 1803 (10.0.17134.0) onward. C++/WinRT is implemented entirely in header files, and designed to provide you with first-class access to the modern Windows API.
With C++/WinRT, you can both consume and author Windows Runtime APIs using any standards-conformant C++17 compiler. C++/WinRT typically performs better and produces smaller binaries than any other language option for the Windows Runtime. We will continue to support C++/CX and WRL, but highly recommend that new applications use C++/WinRT. For more information, see C++/WinRT.

Changes:

  • Replaced ref class with winrt::implements<>
  • Converted Platform::String^ to winrt::hstring
  • Updated event handlers to use C++/WinRT delegates with proper cleanup
  • Replaced ref new with winrt::make<>
  • Updated async helpers to use C++/WinRT IAsyncOperation and exception handling
  • Removed some duplicate includes that weren't needed
  • Added specific Xbox model detection (One, One S, One X, Series S, Series X) via Gaming Device Information API (this changes it from Xbox One/Series CPU in the system info to actually show what console the user is on)
Click to see Console Screenshot image
Click to see Desktop Screenshot image

Reviewers

@LibretroAdmin

@SternXD
Copy link
Copy Markdown
Contributor Author

SternXD commented Dec 31, 2025

whoops let me fix the CI :/

- Replace ref class with winrt::implements<>
- Convert Platform::String^ to winrt::hstring
- Update event handlers to C++/WinRT delegates
- Add PackageReference for auto NuGet restore
- Add specific Xbox model CPU detection via Gaming Device Info API

Signed-off-by: SternXD <[email protected]>
@LibretroAdmin
Copy link
Copy Markdown
Contributor

Is this also more backwards compatible?

@SternXD
Copy link
Copy Markdown
Contributor Author

SternXD commented Jan 2, 2026

Is this also more backwards compatible?

No change same minimum Windows/UWP targets. This is about future-proofing and maintainability, not expanding backwards compatibility. And more partially because I find C++/CX disgusting to work with

@LibretroAdmin
Copy link
Copy Markdown
Contributor

Alright, let's take a gamble on this

@LibretroAdmin LibretroAdmin merged commit 367d2ee into libretro:master Jan 2, 2026
34 checks passed
@SternXD
Copy link
Copy Markdown
Contributor Author

SternXD commented Jan 2, 2026

@LibretroAdmin still going to reply to that message you deleted this is what I was going to say

For the most part yes, but with a clarification: C++/CX isn’t CLR-based (that would be C++/CLI), though it does add a compiler-generated projection layer. Moving to C++/WinRT removes that layer and uses a header-only, standard C++17 projection. That usually means less "glue" code, better inlining, and lower overhead at WinRT boundaries, Though in practice the performance gains are modest and mostly show up in hot paths that frequently cross WinRT boundaries. The main benefits are cleaner semantics, smaller binaries, and long-term maintainability rather than large raw speedups.

@LibretroAdmin
Copy link
Copy Markdown
Contributor

@LibretroAdmin still going to reply to that message you deleted this is what I was going to say

For the most part yes, but with a clarification: C++/CX isn’t CLR-based (that would be C++/CLI), though it does add a compiler-generated projection layer. Moving to C++/WinRT removes that layer and uses a header-only, standard C++17 projection. That usually means less "glue" code, better inlining, and lower overhead at WinRT boundaries, Though in practice the performance gains are modest and mostly show up in hot paths that frequently cross WinRT boundaries. The main benefits are cleaner semantics, smaller binaries, and long-term maintainability rather than large raw speedups.

Sounds great to me. I am also not a fan of having to go through the CLR. The more we can avoid it the better

Comment thread uwp/uwp_async.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants