C++ Engine Porting to UWP
Introduction
This solution is applicable to all C++-based game engines and applications, including Unreal Engine, Cocos2d-x, custom engines, etc. By utilizing MSIX packaging technology while keeping the existing code architecture largely unchanged, traditional Win32 applications can be converted into the UWP format for distribution via the Microsoft Store.
Overall Process Overview
SDK Integration and EXE Build
This stage is fundamental to ensure the game itself is fully functional.
SDK Integration
In your C++ project, follow the standard SDK integration guide to complete tasks such as importing dependent libraries, API calls, and configuration settings. Make sure to complete all SDK-related functionality development and testing at this stage.
Building the Original C++ Application:
-
Use Visual Studio to build your C++ project, outputting a standard Win32 .exe file.
-
Ensure all dependent libraries (such as DLLs) and resource files (images, configurations, etc.) are located in the same directory.
-
It is recommended to use static linking to reduce external dependencies.
# Example output structure
MyGame/
├── MyGame.exe
├── SDL2.dll
├── assets/
│ ├── textures/
│ └── config.json
└── resources/
Handling Sandbox Compatibility
The MSIX sandbox environment restricts some operations that are available by default in Win32, such as accessing the registry or system file directories.
-
File System Access: Applications may attempt to write data to protected paths like
C:\Program Filesor the installation directory, which will fail. Data should be written toWindows.Storage.ApplicationData.Current.LocalFolder(corresponding to%USERPROFILE%\AppData\Local\Packages\[Package Name]\LocalState). -
Registry Access: Applications may read from or write to
HKEY_LOCAL_MACHINEorHKEY_CURRENT_USER\Software\[Some Global Settings]. These write operations will be redirected to a virtualized area. Applications should be guided to store settings inHKEY_CURRENT_USER\Software\Classes\Local Settings\Software\[Application Name]。 -
Inter-process Communication (IPC): Complex IPC may be blocked. Ensure the communication method works within the sandbox.
-
Testing and Debugging: Thorough testing is essential to verify that all SDK functionalities behave consistently in the MSIX-installed version compared to the traditional EXE version.
Building, Testing, and Distribution
-
Generate MSIX Package: Use MSIX packaging technology to generate the final MSIX package for the Microsoft Store.
-
Local Testing: Install the MSIX package and perform comprehensive functionality tests.
-
Run WACK: Use the Windows App Certification Kit (WACK) to run certification tests on the package and resolve any compatibility issues.
-
Store Submission: Submit the certified MSIX package to Microsoft Partner Center to complete the store listing process.
Note: Set your local computer to Developer Mode, otherwise the UWP application cannot be installed normally.
Precautions and Limitations
-
Certain high-risk APIs (such as global hooks, driver loading) are not supported, which may affect anti-cheat modules.
-
The application runs in an isolated container, and writes to the registry and system paths are redirected (Virtualization).
-
Background task extensions are supported (requires additional declaration).