将SDK与Windows 10更新同步并将WinRT与Standard C ++一起使用 [英] synchronizing SDK with Windows 10 update and using WinRT with Standard C++

查看:408
本文介绍了将SDK与Windows 10更新同步并将WinRT与Standard C ++一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已开始使用Visual Studio 2017社区版尝试C ++ / WinRT。我现在有一个环境,可以在其中构建示例应用程序的调试版本并运行它。我必须:




  • 下载并安装最新的Windows 10 SDK

  • 使用以下命令更新Visual Studio 2017 C ++ / WinRT软件包和模板

  • 将Windows 10操作系统更新为最新版本,版本1803



文档和网页描述了C ++ / WinRT软件包对Visual Studio的更新,并且尝试编译该示例使我出现错误,指示下载并安装最新的Windows 10 SDK。



是当我尝试实际运行示例应用程序的调试版本时,发现我还需要Windows 10 Build 1803。



Windows 10 Build 1803 a使用Stadard C ++和C ++ / WinRT运行应用程序的要求还是我的经验是由于使用Debug版本?



这是否意味着尚未升级Windows 10的人安装到至少Windows 10 Build 1803上将无法运行使用C ++ / WinRT开发的应用程序?



是否可以企业或商业客户在从具有自己特定更新集的自有服务器进行企业特定升级时,会选择消除必要的C ++ / WinRT组件,从而使C ++ / WinRT应用程序无法在其环境中运行? / p>

是否有某种包装,以便应用程序可以包含必需的C ++ / WinRT组件?



附录:两个测试应用程序



我从头开始重试了我使用过的两个测试应用程序。重试工作是在修改安装最新的Windows 10 SDK 10.0.17134,安装C ++ / WinRT Visual Studio扩展并将我的PC更新到Windows 10 1803之后进行的。



我尝试的第一个C ++ / WinRT应用程序是Kenny Kerr文章中的控制台应用程序, C ++-引入了具有以下示例应用程序的C ++ / WinRT

  #pragma comment( lib, windowsapp)
#include winrt / Windows.Foundation.h
#include winrt / Windows.Web.Syndication.h
使用命名空间winrt;
使用命名空间Windows :: Foundation;
使用命名空间Windows :: Web :: Syndication;
int main()
{
initialize(); // //注意:生成编译器错误C3861:初始化:找不到标识符
Uri uri(L http://kennykerr.ca/feed);
SyndicationClient客户;
SyndicationFeed feed = client.RetrieveFeedAsync(uri).get();
for(SyndicationItem item:feed.Items())
{
hstring title = item.Title()。Text();
printf(%ls\n,title.c_str());
}
}

我终于提出了创建,编译,并运行此测试源如下。从打开Visual Studio 2017社区版开始,我做了以下工作:




  • 文件->新建->项目并使用Windows桌面,Windows控制台应用程序模板

  • 保留 #include stdafx.h ,但替换生成的模板 main(),并带有上述来源

  • 在解决方案资源管理器中右键单击解决方案,选择属性,打开C / C ++->语言并将 C ++语言标准更改为 ISO C ++ 17 Standard(/ std:c ++ 17)



配置属性中的 Windows SDK版本-> 常规设置为10.0.17134.0。



生成失败,编译错误为错误C3861:'initialize':找不到标识符。进一步的搜索找到了这篇文章, cppwinrt.exe Windows SDK ,其中包含使用 init_apartment(); 而不是 initialize(); 的示例应用程序因此,随着这一更改,我的示例应用程序将编译并运行,并生成一系列文章作为输出。



此Microsoft文档文章使用C ++ / WinRT入门(具有控制台)使用 init_apartment(); 而不是 initialize()的示例。该示例也是一个联合供稿源,但具有不同的URL。



第二个测试应用程序使用 Windows Universal的C ++ / WinRT模板-> Blank App(C ++ / WinRT),生成了一个已编译并运行的示例应用程序。在属性->常规对话框中,目标平台版本设置为10.0.17134.0,目标平台最低要求设置为10.0.15063.0。

解决方案

C ++ / WinRT投影只是C ++头文件。就它们自己而言,除了您正在使用的Windows运行时API之外,它们没有特定的运行时要求。



真正的问题是您在应用程序中使用了哪些API(通过C ++ / WinRT或使用C ++ / CX语言扩展(也称为 / ZW )),以及您设置为 WindowsTargetPlatformMinVersion 在构建UWP应用程序时的价值。



WindowsTargetPlatformVersion 设置为最新的Windows 10 SDK(17134),您可以将UWP应用的最低操作系统版本设置为17134、16299、15063、14393、10586或10240。您需要在该版本上测试您的应用,并确保您禁止使用较新的API。


从实际的角度来看,您不需要支持10240,这就是Visual Studio中新项目的默认值为10586的原因。 ,14393年与您在现实世界中可能遇到的年龄一样古老。



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.

解决方案

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.

这篇关于将SDK与Windows 10更新同步并将WinRT与Standard C ++一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆