Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

visual c++ - synchronizing SDK with Windows 10 update and using WinRT with Standard C++

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
", 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...