c++ - C++/WinRT 到底是什么?

标签 c++ windows c++-winrt

我一直在网上搜索。我得到that :

C++/WinRT is provided as a standard C++17 header file library

但它到底是什么?它是古老的 Win32 API 的新的面向对象替代品吗?它是 Windows 上 Qt 框架的替代品吗?它是一个网络库吗(大多数示例似乎与网络有关)。它是一个GUI框架吗?这是编写新 Windows 应用程序的首选方式吗?它是臭名昭著的 MFC 库的替代品吗?

最佳答案

IInspectable 的答案实际上是正确的,但更多的上下文可能也会有所帮助......

C++/CX(又名 Visual C++ /ZW 开关)、Windows 运行时库 (WRL) 和 C++/WinRT 都执行基本相同的操作:提供调用“Windows 运行时”的机制来自 C++ 的样式 API 和类型,以及用于创作“Windows 运行时”样式 API 和类型。

OP 问题涉及到一个更基本的问题:Windows 运行时 API 的意义是什么?

最初的 Win32 API 是为 native 代码世界设计的,大多数程序都是用 C 或 C++ 编写的。组件对象模型 (COM) 是作为使用相同的基本应用程序二进制接口(interface) (ABI) 处理运行时版本控制(以及许多其他功能)的一种方式而创建的。 C++ 是使用 COM 的更自然的方式,但从技术上讲,您仍然可以通过各种宏等来使用 C。

.NET 和其他托管语言后来出现,并使用不同的调用机制。您可以使用 native 互操作来访问 Win32 或 COM API,但它们通常不会以非常“C# 友好”的方式工作。创建的各种“包装程序集”提供了一种更自然的 C# 方式来访问基本的 C/C++ API 和类型。

随着互联网,特别是万维网的发展,另一类应用程序是使用 HTML5+JavaScript 编写的。他们没有对 Win32 或 COM API 的任何特定访问权限,因此编写了特殊的模块和库来弥补功能差距。

SO考虑到所有这三种主要方法,“Windows 运行时”风格是一种将 COM 的功能与 .NET 的反射丰富的元数据相结合的方法。这个想法是 API 可以编写一次并可由 C++、C# 和 HTML5+JavaScript 使用。

当然,除了能够调用 ABI 之外,使用 API 还存在很多问题,并且每种语言范例都非常不同,但从系统编程的角度来看,这就是重点。

还有一个使用 Windows 运行时 API 的“通用 Windows 平台”,它本身具有三个基本“应用程序模型”:XAML、DirectX 和 XAML+DirectX。如果这些应用程序是用 C++ 编写的,则可以大量使用 C++/WinRT,但您也可以使用 Win32 桌面应用中的 Windows 运行时 API。

WRL is really "ATL 2.0" and was the first attempt at a solution for C++ interop with Windows Runtime APIs. You can use it to consume and author Windows Runtime types but it's a fair amount of manual work and not documented publicly very well. The primary utility in Win32 desktop applications is the Microsoft::WRL::ComPtr smart-pointer.

If you want to know why C++/CX exists, see this blog series. It was intended to be an easy-to-use model for C++, but it's often conflated with Managed C++ (it uses the same reserved keywords, but is not at all related to Managed C++ or .NET) and not supported by other compilers.

If you want to know more about the general reason for C++/WinRT, see this MSDN Magazine article. This is intended to be a much more C++-friendly way to use Windows Runtime APIs, is portable to other non-Microsoft compilers, and is increasingly being used both internally and externally for Windows Runtime development. It does require C++17 language features and therefore pushes hard on the quality of your C++ compiler.

关于c++ - C++/WinRT 到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60021694/

相关文章:

c++ - 为什么析构函数在显式调用时不会在模板化指针上被调用?

c++ - 在 C++ winrt 导航 View 中,如何找到已选择/单击的导航项?

C++ STL Vector 相当于 Rust 中的 set_len()

windows - 在windows10中安装python2.7的natlink和dragonfly

windows - 用于服务发现的 Docker DNS 按名称解析 Windows 容器地址的工作效果不一致

windows - 如何阻止我的安装程序触发 Windows 1 0's "此应用程序已被阻止以保护您的错误?

visual-studio - 在单个 "Windows Runtime Component C++/WinRT"项目中使用多个 .IDL (MIDL) 文件的正确方法

c++ - 我怎么知道我是在开发 c++/cx 还是 c++/WinRT UWP 应用程序?

c++ - gfortran makefile 问题

c++ - 它是否等同于使用 null iv 执行 CBC 模式?