Page 14 - MSDN Magazine, May 2018
P. 14
UNIVERSAL WINDOWS PLATFORM
Closing UWP-Win32
Gaps
Andrew Whitechapel
One of the important themes for the latest update of Windows has been to close the gaps between the Universal Windows Platform (UWP) and traditional Win32 app models. As part of this effort, Microsoft introduced three major enhancements:
• Multi-instancing
• Console UWP apps
• Broader file-system access
The features are related but largely independent. That is, you can create a multi-instanced app that’s either a regular windowed app or a console app—and it may or may not need broader file-system access. Equally, you can create a regular non-console, non-multi- instance app that has broad file-system access. One restriction is that a console app must be configured to support multi-instancing.
Multi-Instancing
In Win32, Linux and other app model environments, multi- instancing has always been the default. In the UWP, in stark contrast, the default has always been single-instancing—and, in fact, multi-instancing wasn’t supported at all until now.
Without multi-instancing, some apps have resorted to a multi-windowing architecture instead, which typically involves sig- nificant work—and results in complexity and fragility. You have to spend a lot of effort in managing your windows, instead of focusing on your domain requirements. Single-process multi-windowing also suffers from reliability concerns: If the single instance crashes, it brings down all its windows; this isn’t true for multi-instancing, where each instance runs as a separate process.
In the single-instance model, the user can activate an app in a number of ways: via a tile-tap in Start; via a URL or protocol acti- vation; by double-clicking a file with an extension that’s registered to the app; and so on. The first activation (of any kind) launches the app. After that, any subsequent activations simply call into the run- ning instance of the app, which the app can handle by overriding the OnActivated method.
The new multi-instancing feature enables UWP apps to work like Win32 apps: If an instance of an app is running and a subse- quent activation request is received, the platform won’t call in to activate the existing instance. Instead, it will create a new instance in a separate process.
This article discusses:
• Adding multi-instancing capabilities to UWP apps • Creating console UWP apps
• Granting broader file-system access to UWP apps Technologies discussed:
Universal Windows Platform, Win32
Code download available at:
bit.ly/2GtzM3T
10 msdn magazine