{"id":14655,"date":"2017-04-17T17:06:39","date_gmt":"2017-04-18T01:06:39","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=14655"},"modified":"2019-02-18T17:48:34","modified_gmt":"2019-02-18T17:48:34","slug":"universal-windows-platform-development-with-c","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/universal-windows-platform-development-with-c\/","title":{"rendered":"Universal Windows Platform Development with C++"},"content":{"rendered":"<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/windows\/uwp\/get-started\/universal-application-platform-guide\">Universal Windows Platform<\/a>\u00a0(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. \u00a0<span>Because a\u00a0app can run\u00a0on 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. \u00a0In 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. \u00a0Adaptive UI controls and new layout panels help you to tailor your UI across a broad range of device screen resolutions and sizes.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwp.png\" alt=\"uwp\" width=\"746\" height=\"311\" class=\"alignnone size-large wp-image-14665\" \/><\/p>\n<p>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:<\/p>\n<ul>\n<li><a href=\"#installation\">Acquiring the tools<\/a><\/li>\n<li><a href=\"#opening\">Opening code and building<\/a><\/li>\n<li><a href=\"#creating\">Creating new projects<\/a><\/li>\n<li><a href=\"#editing\">Editing code and navigating<\/a><\/li>\n<li><a href=\"#debugging\">Debugging and diagnostics<\/a><\/li>\n<li><a href=\"#testing\">Testing<\/a><\/li>\n<li><a href=\"#teamwork\">Working with others<\/a><\/li>\n<li><a href=\"#packaging\">Windows Store packaging<\/a><\/li>\n<\/ul>\n<h2>C++ and the\u00a0Universal Windows Platform<\/h2>\n<p>There are a few ways to write a C++ UWP app:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/cppcx\/visual-c-language-reference-c-cx\">C++\/CX<\/a> is Microsoft&#8217;s language extension for C++ that allows it to target the Windows Runtime that was released with Windows 8 and continues to evolve with Windows 10.<\/li>\n<li>The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh438466.aspx\">Windows Runtime Library<\/a> is a template library that provides a low-level way to author and use Windows Runtime components.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/cppwinrt\">C++\/WinRT<\/a> is a recently implemented standard C++ language projection for the Windows Runtime implemented solely in header files. It allows you to both author and consume Windows Runtime APIs using any standards-compliant C++ compiler. C++\/WinRT is designed to provide C++ developers with first-class access to the modern Windows API.A recent alternative called CppWinRT is a language conformant wrapper for the WinRT APIs that allows you to use modern and compliant C++ code to targets Windows 10.<\/li>\n<\/ul>\n<h2 id=\"installation\">Acquiring the tools<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwpwl.png\" alt=\"uwpwl\" width=\"485\" height=\"94\" class=\"alignnone size-large wp-image-14675\" \/><\/p>\n<p>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 &#8220;C++ Universal Windows Platform tools&#8221;:<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?attachment_id=14685\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwpwloptions.png\" alt=\"uwpwloptions\" width=\"254\" height=\"312\" class=\"alignnone size-large wp-image-14685\" \/><\/a><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?attachment_id=14685\"><\/a><\/p>\n<h2 id=\"opening\">Opening code and building<\/h2>\n<p>Universal Windows Platform apps use Microsoft\u2019s own build system called <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/0k6kkbsd.aspx\">MSBuild<\/a>, which uses the same .vcxproj file format that is used in the new project templates for desktop development.<\/p>\n<p>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 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms164311.aspx\">using the command prompt<\/a>.<\/p>\n<h2 id=\"creating\">Creating new projects<\/h2>\n<p>The UWP development tools provide a number of different templates for you to choose from, including templates for DirectX 11 and Direct X12.\u00a0 A Windows Runtime Component is very similar to a library, but only uses the WinRT APIs available to modern Windows applications.\u00a0 These components can be shared across all supported Windows Runtime languages that support UWP development, which include C#, Visual Basic, JavaScript, and C++.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwptemplate.png\" alt=\"uwptemplate\" width=\"879\" height=\"412\" class=\"alignnone size-large wp-image-14695\" \/><\/p>\n<p>In order to deploy local UWP applications in Windows 10, you must first enable &#8220;Developer mode&#8221; 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwpmode-1024x368.png\" alt=\"uwpmode\" width=\"879\" height=\"316\" class=\"alignnone size-large wp-image-14687\" \/><\/p>\n<p>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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/uwpcube-1024x796.png\" alt=\"uwpcube\" width=\"741\" height=\"576\" class=\"alignnone wp-image-14705\" \/><\/p>\n<h2 id=\"editing\">Editing code and navigating<\/h2>\n<p>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 <strong>Navigate To<\/strong>.\u00a0 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/intellisense.png\" alt=\"intellisense\" width=\"413\" height=\"348\" class=\"alignnone size-full wp-image-14585\" \/><\/p>\n<p>You can hover also over any variable, function, or other code symbol and get information about that symbol using the quick info feature.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/infotip.png\" alt=\"infotip\" width=\"406\" height=\"98\" class=\"alignnone size-full wp-image-14575\" \/><\/p>\n<p>There are also many great code navigation features to make dealing with large code based much more productive, including <strong>Go To Definition<\/strong>, <strong>Go To Line\/Symbols\/Members\/Types<\/strong>, <strong>Find All References<\/strong>, <strong>View Call Hierarchy,<\/strong> <strong>Object Browser<\/strong>, and more.\u00a0 <strong>Peek Definition<\/strong> allows you to view the code that defines the selected variable without even having to open another file which minimizes context switching.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/codepeak.png\" alt=\"codepeak\" width=\"560\" height=\"381\" class=\"alignnone size-full wp-image-14555\" \/><\/p>\n<p>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.<\/p>\n<h2 id=\"debugging\">Debugging and diagnostics<\/h2>\n<p>Debugging applications is what Visual Studio is famous for!\u00a0 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/datatip.png\" alt=\"datatip\" width=\"855\" height=\"107\" class=\"alignnone size-full wp-image-14556\" \/><\/p>\n<p>Powerful features like the advanced breakpoints, custom data visualization, and debug-time profiling enable you to have full control of your app\u2019s execution and pinpoint even the hardest to find bugs.\u00a0 View data values from your code with debugger data tips.\u00a0 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.\u00a0 Track live CPU and memory usage while your application runs and monitor performance in real-time.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/hub.png\" alt=\"hub\" width=\"452\" height=\"462\" class=\"alignnone size-full wp-image-14625\" \/><\/p>\n<h2 id=\"testing\">Testing your code<\/h2>\n<p>Unit testing is a very popular way of improving code quality, and test-driven-development is fully supported inside Visual Studio.\u00a0 Create new tests and <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh419385.aspx\">manage them inside the Test Explorer<\/a> for easy management and execution of tests.\u00a0 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh598953.aspx\">Writing unit tests is easy<\/a> and can help find problems as they arise instead of later on when things are harder to isolate.\u00a0 Visual Studio allows both native and managed test project templates for testing native code which can be found in the <em>Visual C++<\/em><em>\u00e0<\/em><em>Test<\/em> section of the new project templates.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/test.png\" alt=\"test\" width=\"372\" height=\"517\" class=\"alignnone size-full wp-image-14645\" \/><\/p>\n<h2 id=\"teamwork\">Working with others<\/h2>\n<p>Besides all of the individual developer activities that Visual Studio makes more productive, collaboration is also something that is directly integrated into the IDE.\u00a0 Visual Studio Team Services is a suite of features that optimize the team collaboration process for software development organizations.\u00a0 Create work items, track progress, and manage your bug and open issue database all from inside Visual Studio.\u00a0 Git is fully supported and works seamlessly with the Team Explorer, allowing for easy management of branches, commits, and pull requests.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teamexp.jpg\" alt=\"teamexp\" width=\"456\" height=\"339\" class=\"alignnone wp-image-14635\" \/><\/p>\n<h2 id=\"packaging\">Packaging your app for the Windows Store<\/h2>\n<p>There are few steps required to package your app so that you can distribute it on the Windows Store.\u00a0 First, make sure you are a <a href=\"https:\/\/developer.microsoft.com\/en-us\/store\/register\">registered Windows app developer<\/a>.\u00a0 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).\u00a0 This <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/packaging\/packaging-uwp-apps\">detailed packaging guide<\/a> will walk you through the rest of steps needed to get your app ready for distribution and <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/publish\/app-submissions\">submit it to the Windows Store<\/a>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/packaging.png\" alt=\"packaging\" width=\"740\" height=\"424\" class=\"alignnone size-full wp-image-14657\" \/><\/p>\n<h2>Try out Visual Studio 2017 for UWP development with C++!<\/h2>\n<p><a href=\"https:\/\/aka.ms\/vs\/15\/release\/vs_Community.exe\">Download Visual Studio 2017<\/a>, try it out and share your feedback.\u00a0 For problems, let us know via the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a> option in the upper right corner of the VS title bar. \u00a0Track your feedback on the <a href=\"https:\/\/developercommunity.visualstudio.com\/index.html\">developer community portal<\/a>. For suggestions, let us know through <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">UserVoice<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Universal Windows Platform\u00a0(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. \u00a0Because a\u00a0app can run\u00a0on a wide variety of devices with different form factors and types of input, you want it to be tailored [&hellip;]<\/p>\n","protected":false},"author":295,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>Universal Windows Platform\u00a0(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. \u00a0Because a\u00a0app can run\u00a0on a wide variety of devices with different form factors and types of input, you want it to be tailored [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/14655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/295"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=14655"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/14655\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=14655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=14655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=14655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}