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

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

问题描述

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

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:

  • 下载并安装最新的 Windows 10 SDK
  • 使用 C++/WinRT 包和模板更新 Visual Studio 2017
  • 将 Windows 10 操作系统更新到最新版本,版本 1803

文档和网页描述了 Visual Studio 的 C++/WinRT 包更新,尝试编译示例时出现错误,提示我下载并安装最新的 Windows 10 SDK.

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.

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

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.

Windows 10 Build 1803 是使用标准 C++ 和 C++/WinRT 运行应用程序的必要条件,还是我的经验源于使用调试版本?

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?

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

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?

企业或商业客户是否有可能在使用自己的特定更新集从自己的服务器进行企业特定升级时选择消除必要的 C++/WinRT 组件,从而使 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?

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

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

附录:两个测试应用程序

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

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.

我尝试的第一个 C++/WinRT 应用程序是来自 Kenny Kerr 的文章中的控制台应用程序,C++ - 介绍 C++/WinRT,其中包含以下示例应用程序:

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());
  }
}

我终于梳理出一个创建、编译和运行这个测试源的过程如下.从打开 Visual Studio 2017 Community Edition 开始,我做了以下工作:

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:

  • 文件 -> 新建 -> 项目和使用 Windows 桌面、Windows 控制台应用程序模板
  • 保留 #include "stdafx.h" 但将模板生成的 main() 替换为上述源
  • 在解决方案资源管理器中右键单击解决方案,选择属性,打开 C/C++ -> 语言并将C++ 语言标准"更改为ISO C++17 标准 (/std:c++17)"
  • 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)"

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

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

构建失败,编译错误 error C3861: 'initialize': identifier not found.进一步搜索发现这篇文章,cppwinrt.exe 在Windows SDK,其中包含一个使用 init_apartment(); 而不是 initialize(); 的示例应用程序,因此通过该更改,我的示例应用程序编译并运行生成文章列表作为输出.

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.

这篇 Microsoft 文档文章,C++/WinRT 入门,日期为 05/07/2018,有一个使用 init_apartment(); 而不是 initialize() 的控制台示例.该示例也是一个联合供稿,但指向不同的 URL.

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.

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

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.

推荐答案

C++/WinRT 投影只是 C++ 标头.除了您使用的 Windows 运行时 API 之外,它们本身没有特定的运行时要求.

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

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

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.

WindowsTargetPlatformVersion 设置为最新的 Windows 10 SDK (17134),您可以将 UWP 应用所需的最低操作系统版本设置为 17134、16299、15063、14393、10586 或 10240.您'将需要在该版本上测试您的应用程序,并确保您保护任何新 API 的使用.

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.

从实际的角度来看,您不需要支持 10240,这就是为什么 Visual Studio 中新项目的默认值是 10586.对于消费者版本,14393 与您在现实世界中可能遇到的一样旧.

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 与标准 C++ 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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