Universal Windows Platform Development with C++

uwp

Universal Windows Platform (UWP) applications utilize a new Windows API and app model that creates a single output binary that can feasibly run on any Windows 10 device, ranging from desktops to HoloLens. Because a app can run on a wide variety of devices with different form factors and types of input, you want it to be tailored to each device and be able to unlock the unique capabilities of each device. In addition to the guaranteed core API layer, you can write code to access device specific APIs so that your app lights up features specific to one type of device while presenting a different experience on other devices. Adaptive UI controls and new layout panels help you to tailor your UI across a broad range of device screen resolutions and sizes. In this blog post we will dive into the specifics of how to create a C++ UWP application and how Visual Studio makes this a great experience:

C++ and the Universal Windows Platform

There are a few ways to write a C++ UWP app:

Acquiring the tools

uwpwl

The Visual Studio workload that provides the tools for creating UWP apps and has an optional installation component that is required for C++ UWP development called “C++ Universal Windows Platform tools”:

uwpwloptions

Opening code and building

Universal Windows Platform apps use Microsoft’s own build system called MSBuild, which uses the same .vcxproj file format that is used in the new project templates for desktop development.

MSBuild is a robust and fully featured build system that allows building projects in Visual Studio that target Windows. Building an MSBuild-based project just requires a .vcxproj file and can be built in the IDE or using the command prompt.

Creating new projects

The UWP development tools provide a number of different templates for you to choose from, including templates for DirectX 11 and Direct X12. A Windows Runtime Component is very similar to a library, but only uses the WinRT APIs available to modern Windows applications. These components can be shared across all supported Windows Runtime languages that support UWP development, which include C#, Visual Basic, JavaScript, and C++.

uwptemplate

In order to deploy local UWP applications in Windows 10, you must first enable “Developer mode” which can be done after creating a UWP project. This will find and install the latest packages for Store app deployment and allow you to deploy the UWP apps you develop in Visual Studio.

uwpmode

After activating developer mode in Windows 10, you can now build and deploy Universal Windows Platform applications, like this spinning cube that is provided in the DirectX templates.

uwpcube

Editing code and navigating

Visual Studio provides many features that help you to code correctly and more efficiently. Whether it be the powerful predictive capabilities provided by IntelliSense or the fluid navigation found in Navigate To. Let Visual Studio do the work for you with autocompletion simply by pressing Tab on the item you want to add from the member list.

intellisense

You can hover also over any variable, function, or other code symbol and get information about that symbol using the quick info feature.

infotip

There are also many great code navigation features to make dealing with large code based much more productive, including Go To Definition, Go To Line/Symbols/Members/Types, Find All References, View Call Hierarchy, Object Browser, and more. Peek Definition allows you to view the code that defines the selected variable without even having to open another file which minimizes context switching.

codepeak

We also have support for some of the more common refactoring techniques like rename and extract function that allow you to keep your code looking nice and consistent.

Debugging and diagnostics

Debugging applications is what Visual Studio is famous for! With a world-class debugging experience that provides a plethora of tools for any type of app, no tool is better suiting to debugging applications that target the Windows desktop platform.

datatip

Powerful features like the advanced breakpoints, custom data visualization, and debug-time profiling enable you to have full control of your app’s execution and pinpoint even the hardest to find bugs. View data values from your code with debugger data tips. Take memory snapshots and diff them to reveal potential memory leaks, and even invoke PageHeap on your app from inside Visual Studio to help solve the notoriously hard problem of memory corruption. Track live CPU and memory usage while your application runs and monitor performance in real-time.

hub

Testing your code

Unit testing is a very popular way of improving code quality, and test-driven-development is fully supported inside Visual Studio. Create new tests and manage them inside the Test Explorer for easy management and execution of tests. Writing unit tests is easy and can help find problems as they arise instead of later on when things are harder to isolate. Visual Studio allows both native and managed test project templates for testing native code which can be found in the Visual C++àTest section of the new project templates.

test

Working with others

Besides all of the individual developer activities that Visual Studio makes more productive, collaboration is also something that is directly integrated into the IDE. Visual Studio Team Services is a suite of features that optimize the team collaboration process for software development organizations. Create work items, track progress, and manage your bug and open issue database all from inside Visual Studio. Git is fully supported and works seamlessly with the Team Explorer, allowing for easy management of branches, commits, and pull requests.

teamexp

Packaging your app for the Windows Store

There are few steps required to package your app so that you can distribute it on the Windows Store. First, make sure you are a registered Windows app developer. Once you are registered and have a tested and optimized app you are interested in publishing, you can select your packaging options in the app manifest file (package.appxmanifest). This detailed packaging guide will walk you through the rest of steps needed to get your app ready for distribution and submit it to the Windows Store.

packaging

Try out Visual Studio 2017 for UWP development with C++!

Download Visual Studio 2017, try it out and share your feedback. For problems, let us know via the Report a Problem option in the upper right corner of the VS title bar. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice.