synchronizing SDK with Windows 10 update and using WinRT with Standard C++
Asked Answered
A

1

1

I have started experimenting with C++/WinRT using Visual Studio 2017 Community Edition. I now have an environment in which I can build a debug version of a sample application and run it. I had to:

  • download and install latest Windows 10 SDK
  • update Visual Studio 2017 with the C++/WinRT package and templates
  • update Windows 10 OS to the latest build, build 1803

Documentation and web pages described the C++/WinRT package update to Visual Studio and trying a compile of the example gave me an error indicating to download and install the latest Windows 10 SDK.

It was when I tried to actually run the debug build of the sample application that I found out I also needed Windows 10 Build 1803.

Is Windows 10 Build 1803 a requirement for running an application using Stadard C++ and C++/WinRT or was my experience due to using a Debug build?

Does this mean that people who have not upgraded their Windows 10 installation to at least Windows 10 Build 1803 will be unable to run an application developed with C++/WinRT?

Is it possible that an Enterprise or business customer will elect to eliminate the necessary C++/WinRT components when they do an Enterprise specific upgrade from their own servers with their own specific set of updates so that a C++/WinRT application will fail to run in their environment?

Is there some kind of packaging so that the necessary C++/WinRT components can be included with the application?

Addendum: Two test applications

I have retried from scratch the two test applications that I have worked with. This retry effort is after making the modifications of installing the latest Windows 10 SDK, 10.0.17134, and installing the C++/WinRT Visual Studio extension and updating my PC to Windows 10 1803.

The first C++/WinRT application that I tried was a console application from an article by Kenny Kerr, C++ - Introducing C++/WinRT which had the following sample application:

#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Web::Syndication;
int main()
{
  initialize();        // NOTE: Generates compiler error C3861: 'initialize': identifier not found
  Uri uri(L"http://kennykerr.ca/feed");
  SyndicationClient client;
  SyndicationFeed feed = client.RetrieveFeedAsync(uri).get();
  for (SyndicationItem item : feed.Items())
  {
    hstring title = item.Title().Text();
    printf("%ls\n", title.c_str());
  }
}

I finally teased out a procedure for creating, compiling, and running this test source was as follows. Starting with opening Visual Studio 2017 Community Edition, I did the following:

  • File -> New -> Project and use Windows Desktop, Windows Console application template
  • keeping the #include "stdafx.h" but replace the template generated main() with the above source
  • right click on solution in Solution Explorer, select Properties, open C/C++ -> Language and change "C++ language standard" to "ISO C++17 Standard (/std:c++17)"

The "Windows SDK Version" in "Configuration Properties" -> "General" was set to 10.0.17134.0.

The build failed with a compilation error of error C3861: 'initialize': identifier not found. Further searches found this article, cppwinrt.exe in the Windows SDK, which contained a sample application that used init_apartment(); instead of initialize(); so with that change my sample application compiles and runs producing a list of articles as output.

This Microsoft docs article, Get started with C++/WinRT, dated 05/07/2018 has a console example that uses init_apartment(); rather than initialize(). That example is also a Syndication Feed but to a different URL.

The second test application used the C++/WinRT template of "Windows Universal" -> "Blank App (C++/WinRT)" which generated a sample application which compiled and ran. In the "Properties" -> "General" dialog the "Target Platform Version" was set to 10.0.17134.0 and the "Target Platform Minimum" was set to 10.0.15063.0.

Accrescent answered 8/5, 2018 at 16:37 Comment(3)
Technically, you don't need the C++/WinRT VSIX extension. You can use a generic (native) Windows application type to implement a C++/WinRT application. Technically, you also don't need the (currently) latest Windows SDK. This is only required, if you need the cppwinrt.exe 'compiler', i.e. if you are authoring Windows Runtime Components, or consuming components that don't ship C++ header files.Kovacev
@Kovacev I am not sure what you mean by "technically" I do not need the latest Windows SDK which seems to be 17134.0 since unless that is my "Target Platform Version" or "Windows SDK Version" (depending on the type of solution, UWP app or console app) I get compiler errors. So 17134.0 seems to be required for a successful compile. It looks to me like the C++/WinRT VSIX extension is not required, as you say, since I was able to create a console application using a Windows Desktop template.Accrescent
That statement wasn't entirely correct. The C++/WinRT header files are only included in the (currently) most recent Windows SDK. Previously you had to download the headers from the - now archived - C++/WinRT GitHub repository, or install the appropriate vcpkg. If you did, you didn't need any particular Windows SDK version. Regardless of that, you are still required to have the header files matching the Target Platform Version you chose (or header files for a later version).Kovacev
I
3

The C++/WinRT projections are just C++ headers. By themselves, they have no particular runtime requirements beyond the Windows Runtime APIs you are consuming.

The real question is what APIs are you using in your application (either via C++/WinRT or using the C++/CX language extensions (a.k.a. /ZW)), and what value you have set as the WindowsTargetPlatformMinVersion value when you build your UWP app.

With WindowsTargetPlatformVersion set to the latest Windows 10 SDK (17134), you can set the minimum required OS version for your UWP app to 17134, 16299, 15063, 14393, 10586, or 10240. You'll need to test your application on that version and make sure you guard any use of newer APIs.

From a practical standpoint, you should not need to support 10240 which is why the default in Visual Studio for a new project is 10586. For consumer editions, 14393 is as old as you are ever likely to encounter in the real-world.

Innings answered 8/5, 2018 at 17:1 Comment(5)
Thank you for your posting. I will need to review what you have written against the sample application which is on a PC at home. I recall, though I may be mistaken, that I tried other targets and saw build errors. I probably need to update my posted question this evening with the actual sample code and some idea as to the specific target and settings.Accrescent
You have to build against the same Windows 10 SDK as you have set for WindowsTargetPlatformVersion and the matching C++/WinRT headers--the 17134 versions are now included in the latest Windows 10 SDK so you no longer need a distinct package. It should still run on an older OS.Innings
I have updated my posted question with a better explanation of two test applications that I am working with. I see what you say about the Target Platform Version should be set to 17134 but the Target Platform Minimum can be something else. I have not tried running this on a Windows 10 box that has not been upgraded yet. I think during the course of investigating and trying things I got a bit confused. What I am reading from your comment is that I either need the Windows SDK 17134 on an older OS version or upgrade to Windows build 1803 but I don't have to do both. Is that correct?Accrescent
You can use the Windows 10 SDK (17134) and the latest C++/WinRT projections that come with it as long as your WindowsTargetPlatformVersion setting is 10.0.17134. You set the WindowsTargetPlatformMinVersion based on which versions of Windows 10 you want to support, which should include your dev/test machine. APIs and API contracts that are associated with newer versions of the OS than your minimum will fail at runtime if you don't properly guard their usage which is no different than Win32 desktop development.Innings
I copied a release build of the C++/WinRT console application as an exe along with a simple .bat file to run it onto another Windows 10 Version 1703 x64 and it ran fine. This PC has VS 2017 Community Edition installed with SDK 10.0.16299.0 installed. I have asked a friend to run a quick test with Windows 10 IoT Enterprise. Thank you for your help.Accrescent

© 2022 - 2024 — McMap. All rights reserved.