简体   繁体   English

C++ 语言投影

[英]C++ language projection

Can you explain in your own words what it means: Standard C++17 language projection for Windows Runtime API (WinRT) (examples are welcome)?你能用自己的话解释一下它的意思吗: Standard C++17 language projection for Windows Runtime API (WinRT)(欢迎举例)?

On the microsovt website, everything is so complicatedly described that I could not understand this term在microsovt网站上,一切都描述得太复杂了,我无法理解这个术语

This confusion goes all the way back to Microsoft's monumental communication disaster in explaining what the Windows Runtime is.这种混淆一直追溯到微软在解释 Windows 运行时是什么时发生的巨大通信灾难。 In broad terms, it is the foundational technology that underpins the "future" of the Windows API (that "future" had arrived well over a decade ago).从广义上讲,它是支撑 Windows API“未来”(“未来”早在十多年前就已到来)的基础技术

The Windows Runtime 1 is based on an evolution of COM , inheriting one of its fundamental properties: A strict ABI contract, enabling language-agnosticism. Windows 运行时1基于COM的演变,继承了其基本属性之一:严格的ABI契约,支持语言不可知论。 Either side of the ABI can be written in just about any programming language. ABI 的任何一侧都可以用几乎任何编程语言编写。

Functionality in the Windows Runtime is deployed by way ofWindows Runtime Components . Windows 运行时中的功能是通过Windows 运行时组件部署的。 WinRT components generally consist of two parts: WinRT组件一般由两部分组成:

  • A WinMD file that describes the provided interfaces in a machine-readable way以机器可读的方式描述提供的接口的WinMD文件
  • A binary that implements the functionality实现功能的二进制文件

While possible to communicate with WinRT components right at the ABI (using either the WRL , or straight C) this can quickly become unwieldy and error prone.虽然可以直接在 ABI 与 WinRT 组件通信(使用WRL或直接 C),但这很快就会变得笨拙且容易出错。 This is where "language projections" come into play: Generally tool- and library-based, they "project" the raw ABI into more manageable, safer abstractions for a given programming language (eg C++ , C# , or Rust ).这就是“语言投影”发挥作用的地方:通常基于工具和库,它们将原始 ABI“投影”为给定编程语言的更易于管理、更安全的抽象(例如C++C#Rust )。

The C++/WinRT language projection provides a large array of translations, including C++/WinRT 语言投影提供了大量的翻译,包括

  • Automatic reference counting, courtesy of thecom_ptr class template自动引用计数,由com_ptr class 模板提供
  • Translation between C++ exceptions and ABI-compatible HRESULT error codes C++ 异常和 ABI 兼容的HRESULT错误代码之间的转换
  • Exposing asynchronous operations as C++20 coroutines将异步操作公开为 C++20 协程
  • Mapping delegates to anything that provides a function call operator (such as functions, member functions, lambda expressions, etc.)将委托映射到任何提供 function 调用运算符的对象(例如函数、成员函数、lambda 表达式等)
  • Seamless translations between WinRT date and time primitives and std::chrono types WinRT 日期和时间基元与std::chrono类型之间的无缝转换
  • Exposing static instance methods as static class members (even though they are technically implemented on the type's activation factory )static实例方法公开为static class 成员(即使它们在技术上是在类型的激活工厂上实现的)
  • ... ...

In short, a language projection makes WinRT types appear as natural as possible for any given language, hiding all aspects of the ABI, with the intention of making the Windows Runtime accessible to programmers that don't (care to) know about the technology's internals.简而言之,语言投影使 WinRT 类型对于任何给定语言看起来尽可能自然,隐藏 ABI 的所有方面,目的是让不(关心)了解该技术内部结构的程序员可以访问 Windows 运行时.

To this day, that plan only really panned out for C# developers (which, ironically, predominantly assume that the Windows Runtime were powered by the CLR ).时至今日,该计划只真正为 C# 名开发人员提供了支持(具有讽刺意味的是,他们主要假设 Windows 运行时由CLR提供支持)。


1 A misnomer, sorry. 1用词不当,抱歉。 It doesn't contain any sort of runtime component in the traditional sense.它不包含任何传统意义上的运行时组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM