简体   繁体   中英

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)?

On the microsovt website, everything is so complicatedly described that I could not understand this term

This confusion goes all the way back to Microsoft's monumental communication disaster in explaining what the Windows Runtime is. 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).

The Windows Runtime 1 is based on an evolution of COM , inheriting one of its fundamental properties: A strict ABI contract, enabling language-agnosticism. Either side of the ABI can be written in just about any programming language.

Functionality in the Windows Runtime is deployed by way ofWindows Runtime Components . WinRT components generally consist of two parts:

  • A WinMD file that describes the provided interfaces in a machine-readable way
  • 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. 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 ).

The C++/WinRT language projection provides a large array of translations, including

  • Automatic reference counting, courtesy of thecom_ptr class template
  • Translation between C++ exceptions and ABI-compatible HRESULT error codes
  • Exposing asynchronous operations as C++20 coroutines
  • Mapping delegates to anything that provides a function call operator (such as functions, member functions, lambda expressions, etc.)
  • Seamless translations between WinRT date and time primitives and std::chrono types
  • Exposing static instance methods as static class members (even though they are technically implemented on the type's activation factory )
  • ...

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.

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 ).


1 A misnomer, sorry. It doesn't contain any sort of runtime component in the traditional sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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