Windows Runtime: Difference between revisions
Undid revision 1027858263 by Jaiganesh.kumaran (talk) |
Add more details about the ABI and clarify what really WinRT is. (Don't revert) |
||
Line 1: | Line 1: | ||
{{Redirect-distinguish|WinRT|Windows RT}} |
{{Redirect-distinguish|WinRT|Windows RT}} |
||
{{Infobox software |
{{Infobox software |
||
| name |
| name = Windows Runtime |
||
| screenshot_size |
| screenshot_size = 300px |
||
| other_names |
| other_names = WinRT |
||
| developer |
| developer = [[Microsoft]] |
||
| released = {{start date and age|2011|9}} |
|||
| replaces |
| replaces = [[Windows API|Win32 API]] |
||
| programming language = [[C++]] |
|||
| engine = [[Component Object Model]] |
|||
| operating system = [[Microsoft Windows]] |
| operating system = [[Microsoft Windows]] |
||
| genre |
| genre = [[Application binary interface]], [[Application programming interface]] |
||
}} |
}} |
||
'''Windows Runtime''' ('''WinRT''') is a platform-agnostic application architecture first introduced in [[Windows 8]] and [[Windows Server 2012]] in 2012. |
'''Windows Runtime''' ('''WinRT''') is a platform-agnostic component and application architecture first introduced in [[Windows 8]] and [[Windows Server 2012]] in 2012. It is implemented in C++ and officially supports development in C++C++ (via [[C++/WinRT]], [[C++/CX]] or WRL), [[Rust_(programming_language)|Rust/WinRT]], [[Python (programming language)|Python/WinRT]], [[JavaScript]]-[[TypeScript]], and the [[managed code]] languages [[C Sharp (programming language)|C#]] and [[Visual Basic .NET]] (VB.NET). |
||
WinRT is not a runtime in a traditional sense but rather a language-independent [[application binary interface]] based on [[Component Object Model|COM]] to allow APIs be consumed from multiple languages but it does provide certain services usually provided by a full blown runtime such as type activation.<ref>{{Cite web|last=Zhang|first=Yi|date=2017-03-15|title=Windows Runtime is not a Runtime|url=http://yizhang82.dev/what-is-winrt|access-date=2021-06-14|website=yizhang82’s blog|language=en}}</ref> Apps using the Windows Runtime may run inside a [[Sandbox (computer security)|sandboxed]] environment to allow greater security and stability and can natively support both [[x86]] and [[ARM architecture|ARM]].<ref>{{cite web |url=http://www.infoq.com/news/2011/09/Design-Details-Windows-Runtime |title=Design Details of the Windows Runtime |first=Abel |last=Avram |date=21 September 2011 |work=InfoQ}}</ref><ref>{{cite web |url=http://www.anandtech.com/show/4771/microsoft-build-windows-8-pre-beta-preview/5 |title=Microsoft Build: Windows 8, A Pre-Beta Preview |first=Brian |last=Klug |first2=Ryan |last2=Smith |date=13 September 2011 |work=[[AnandTech]]}}</ref> WinRT components are designed with interoperability among multiple languages and APIs in mind, including native, managed and scripting languages. Built-in APIs provided by Windows which use the WinRT ABI are commonly known as WinRT APIs however anyone can use the WinRT ABI for their own APIs. |
|||
[[Windows Phone 8.1]] uses a version of the Windows Runtime named the ''Windows Phone Runtime''. It enables developing applications in C# and VB.NET, and Windows Runtime components in C++/CX.<ref>{{cite web|title=Windows Phone API reference|url=https://msdn.microsoft.com/library/windows/apps/ff626516%28v=vs.105%29.aspx|website=Windows Phone API reference|publisher=[[Microsoft]]|date=July 21, 2014}}</ref> |
|||
== Technology == |
== Technology == |
||
WinRT is implemented in the programming language [[C++]]<ref name="rtcpp">{{cite book |title=WinRT Revealed |publisher=[[Apress]] |first=Mayberry |last=Michael |year=2012 |location=New York City |page=3 |isbn=978-1-4302-4585-8}}</ref> and is [[object-oriented programming|object-oriented]] by design.<ref name="rtcpp"/> Its underlying technology, the [[Windows API]] (Win32 API), is written mostly in the language [[C (programming language)|C]].<ref>{{cite web |title=Creating Win32 Applications (C++) |url=http://msdn.microsoft.com/en-us/library/bb384843.aspx |work=[[MSDN]]|publisher=[[Microsoft]] |access-date=12 January 2014}}</ref> It is an [[unmanaged code]] [[application |
WinRT is implemented in the programming language [[C++]]<ref name="rtcpp">{{cite book |title=WinRT Revealed |publisher=[[Apress]] |first=Mayberry |last=Michael |year=2012 |location=New York City |page=3 |isbn=978-1-4302-4585-8}}</ref> and is [[object-oriented programming|object-oriented]] by design.<ref name="rtcpp"/> Its underlying technology, the [[Windows API]] (Win32 API), is written mostly in the language [[C (programming language)|C]].<ref>{{cite web |title=Creating Win32 Applications (C++) |url=http://msdn.microsoft.com/en-us/library/bb384843.aspx |work=[[MSDN]]|publisher=[[Microsoft]] |access-date=12 January 2014}}</ref> It is an [[unmanaged code|unmanaged]] [[application binary interface]] based on [[Component Object Model]] (COM) that allows interfacing from multiple languages, as does COM. However, the API definitions are stored in <code>.winmd</code> files, which are encoded in [[Metadata (CLI)|ECMA 335 metadata]] format, which [[.NET Framework]] also uses with a few modifications. For WinRT components implemented in native code, the metadata file only contains the definition of methods, classes, interfaces and enumerations and the implementation is provided in a separate DLL.<ref>{{cite web |title=Windows Metadata (WinMD) files |url=https://docs.microsoft.com/uwp/winrt-cref/winmd-files |department=API reference for UWP apps |website=[[Microsoft Docs]] |access-date=2019-07-20}}</ref><ref name=icaza>{{cite web |last=De Icaza |first=Miguel |title=WinRT demystified |url=http://tirania.org/blog/archive/2011/Sep-15.html |work=Personal blog of Miguel de Icaza |publisher=[[WP:SPS|Self-published]] |access-date=15 January 2014 |date=15 September 2011}}</ref><ref>{{Cite web|date=2012-10-15|title=WINMD Files Under the Hood|url=https://www.codeproject.com/Articles/476957/WINMDplusFilesplusUnderplustheplusHood|access-date=2021-06-14|website=CodeProject|language=en-US}}</ref> This common metadata format makes it easier to consume WinRT APIs from .NET apps with simpler syntax than [[P/Invoke]].<ref>{{cite web |title=What is the COM marshaling overhead in calling the WinRT API from C#? |url=http://social.msdn.microsoft.com/Forums/windowsapps/en-US/d510d916-a090-412c-a17f-e4421ad9a137/what-is-the-com-marshaling-overhead-in-calling-the-winrt-api-from-c-?forum=winappswithcsharp |work=MSDN forum |publisher=[[WP:SPS|Self-published]]|access-date=15 January 2014|date=20 September 2011}}</ref> {{Unreliable source?|date=January 2014}} Windows provides a set of built-in APIs which are built on the WinRT ABI which provide everything from the [[Windows Runtime XAML Framework|XAML UI framework]] and device access such as camera, microphone etc... |
||
The |
The previous [[C++/CX]] (Component Extensions) language, which borrows some [[C++/CLI]] syntax, was introduced for writing and consuming WinRT components with less [[glue code]] visible to the programmer, relative to classic COM programming in C++, and imposes fewer restrictions relative to C++/CLI on mixing types. The Component Extensions of C++/CX are recommended for use at the API-boundary only, not for other purposes.<ref name="autogenerated1">{{cite web|url=http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-532T |title=Using the Windows Runtime from C++ | Build2011 | Channel 9 |publisher=Channel9.msdn.com |date=2011-09-14 |access-date=2012-04-24}}</ref> Regular C++ (with COM-specific discipline) can also be used to program with WinRT components,<ref>{{cite web|last=Sivakumar |first=Nish |url=http://www.codeproject.com/KB/cpp/WinRTVisualCppIntro.aspx |title=Visual C++ and WinRT/Metro - Some fundamentals - CodeProject® |publisher=Codeproject.com |date=2011-09-29 |access-date=2012-04-24}}</ref> with the help of the Windows Runtime C++ Template Library (WRL), which is similar in purpose to what [[Active Template Library]] provides for COM.<ref>{{cite web|url=http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-532T#c634517976543836549 |title=Using the Windows Runtime from C++ | Build2011 | Channel 9 |publisher=Channel9.msdn.com |date=2011-09-14 |access-date=2012-04-24}}</ref> In 2019, Microsoft deprecated C++/CX in favor of the [[C++/WinRT]] header library.<ref>{{cite web |title=Introduction to C++/WinRT - Windows UWP applications |url=https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt |website=docs.microsoft.com |publisher=Microsoft |language=en-us}}</ref> |
||
WinRT applications run within a sandbox and need explicit user approval to access critical OS features and underlying hardware. By default, file access is restricted to several predetermined locations, such as the directories Documents or Pictures.<ref>{{Cite web|last=lastnameholiu|title=File access permissions - UWP applications|url=https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions|access-date=2020-08-08|website=docs.microsoft.com|language=en-us}}</ref> |
Most WinRT applications run within a sandbox and need explicit user approval to access critical OS features and underlying hardware. By default, file access is restricted to several predetermined locations, such as the directories Documents or Pictures.<ref>{{Cite web|last=lastnameholiu|title=File access permissions - UWP applications|url=https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions|access-date=2020-08-08|website=docs.microsoft.com|language=en-us}}</ref> |
||
WinRT applications |
WinRT applications are packaged in the .appx and later the .msix [[file format]]; based upon [[Open Packaging Conventions]], it uses a [[Zip (file format)|ZIP format]] with added XML files.<ref name=msdn-appx>{{cite web|title=Designing a simple and secure app package – APPX|url=http://blogs.msdn.com/b/windowsappdev/archive/2012/12/04/designing-a-simple-and-secure-app-package-appx.aspx|work=Windows 8 app developer blog|access-date=30 December 2013}}</ref> WinRT applications are distributed mostly through an [[application store]] named [[Microsoft Store (digital)|Microsoft Store]], where Windows apps (termed ''Windows Store apps'') can be purchased and downloaded by users. WinRT apps can only be [[sideloading|sideloaded]] from outside Windows Store on Windows 8 or RT systems that are part of a [[Windows domain]], or equipped with a special activation key obtained from Microsoft.<ref name=installapps>{{cite web |title=How to Add and Remove Apps |url=https://technet.microsoft.com/en-us/library/hh852635.aspx |work=[[Microsoft TechNet|TechNet]] |publisher=Microsoft |date=31 May 2012 |access-date=4 October 2012 |quote=To enable sideloading on a Windows 8 Enterprise computer that is not domain-joined or on any Windows® 8 Pro computer, you must use a sideloading product activation key. To enable sideloading on a Windows® RT device, you must use a sideloading product activation key. For more information about sideloading product activation keys, see Microsoft Volume Licensing.}}</ref><ref name=pcmag-metromess>{{cite web|title=Windows 8: The Metro Mess|url=http://forwardthinking.pcmag.com/none/301689-windows-8-the-metro-mess|publisher=PC Magazine|access-date=8 September 2012}}</ref><ref>{{cite news|title=Microsoft now using 'Modern UI Style' to refer to Windows 8 'Metro Style' apps|url=https://www.theverge.com/2012/8/10/3232921/microsoft-modern-ui-style-metro-style-replacement|access-date=10 August 2012}}</ref><ref>{{cite web|title=What's a Microsoft Store app?|url=http://msdn.microsoft.com/en-us/library/windows/apps/hh974576.aspx|publisher=Windows Dev Center|access-date=1 October 2012}}</ref>These restrictions were lifted in the Windows 10 November Update, where users can freely sideload any app signed with a trusted certificate by enabling a setting.<ref>{{Cite web|date=2019-07-27|title=What Is Sideloading & How To Sideload Apps On Windows 10? [DETAILS]|url=https://silicophilic.com/how-to-sideload-apps-on-windows-10/|access-date=2021-06-14|website=Silicophilic|language=en-US}}</ref> |
||
In a major departure from Win32 and similarly to [[.NET Framework version history#Asynchronous operations|.NET Framework 4.5]], most APIs which are expected to take significant time to complete are implemented as [[wikt:asynchronous|asynchronous]]. |
In a major departure from Win32 and similarly to [[.NET Framework version history#Asynchronous operations|.NET Framework 4.5]], most APIs which are expected to take significant time to complete are implemented as [[wikt:asynchronous|asynchronous]]. When calling a Windows Runtime ABI, the task is started on another thread or process and returns immediately, freeing the app to perform other tasks while waiting for results.<ref>{{cite web |title=Asynchronous programming (Windows Store apps) |url=http://msdn.microsoft.com/en-us/library/windows/apps/hh464924.aspx |work=[[MSDN]] |publisher=[[Microsoft]] |access-date=12 January 2014}}</ref> The asynchronous model requires new programming language constructs. Each language provides their own way to consume [[wikt:asynchronous|asynchronous]] APIs. Parts of the built-in API needing asynchronous access include on-screen messages and dialogs, file access, Internet connectivity, sockets, streams, devices and services, and calendar, contacts and appointments. |
||
== Services == |
== Services == |
||
Line 29: | Line 32: | ||
{{See also|Metadata (CLI)}} |
{{See also|Metadata (CLI)}} |
||
The metadata describes the |
The metadata describes the APIs written using the WinRT ABI. It defines a [[programming model]] that makes it possible to write [[object-oriented]] code that can be shared across [[programming language]]s, and enables services like [[Reflection (programming)|reflection]]. |
||
[[Herb Sutter]], [[C++]] expert at [[Microsoft]], explained during his session on C++ at the 2011 [[Build (developer conference)|Build conference]] that the WinRT metadata is in the same format as [[metadata (CLI)|CLI metadata]].<ref name="autogenerated1"/> Native code (i.e., processor-specific machine code) cannot contain metadata, so it is stored in separate |
[[Herb Sutter]], [[C++]] expert at [[Microsoft]], explained during his session on C++ at the 2011 [[Build (developer conference)|Build conference]] that the WinRT metadata is in the same format as [[metadata (CLI)|CLI metadata]].<ref name="autogenerated1"/> Native code (i.e., processor-specific machine code) cannot contain metadata, so it is stored in a separate metadata file that can be reflected like ordinary [[assembly (CLI)|CLI assemblies]].<ref>{{cite web |url=http://www.ciprianjichici.ro/blog/post/NET-Gets-a-New-Lease-of-Life.aspx |title= .NET Gets a New Lease of Life |access-date=September 16, 2011 |url-status=dead |archive-url=https://web.archive.org/web/20110924132009/http://www.ciprianjichici.ro/blog/post/NET-Gets-a-New-Lease-of-Life.aspx |archive-date=September 24, 2011}}</ref> Since it is the same format as CLI metadata, WinRT APIs can be used from managed [[CLI Languages|CLI languages]] as if it was just a .NET API. |
||
Because it is CLI metadata, code written in native WinRT languages can be used from managed [[list of CLI languages|CLI languages]]. |
|||
=== Type system === |
=== Type system === |
||
WinRT has a rich [[object-oriented]] [[Class (computer programming)|class]]-based [[type system]] that is built on the metadata. It supports constructs with corresponding constructs in the .NET framework: [[Class (computer programming)|classes]], [[Method (computer programming)|methods]], [[properties]], [[Delegation (programming)|delegates]], and [[Event (computing)|events]]. |
WinRT has a rich [[object-oriented]] [[Class (computer programming)|class]]-based [[type system]] that is built on the metadata. It supports constructs with corresponding constructs in the .NET framework: [[Class (computer programming)|classes]], [[Method (computer programming)|methods]], [[properties]], [[Delegation (programming)|delegates]], and [[Event (computing)|events]]. |
||
One of the major additions to WinRT relative to COM is the cross-[[application binary interface]] (ABI), .NET-style [[generic programming|generics]]. In C++/CX |
One of the major additions to WinRT relative to COM is the cross-[[application binary interface]] (ABI), .NET-style [[generic programming|generics]]. Only interfaces and delegates can be generic, runtime classes and methods in them can't. Generic interfaces are also known as parameterized interfaces. In C++/CX, they are declared using the keyword <code>generic</code> with a syntax very similar to that of keyword <code>template</code>. WinRT classes (ref classes) can also be genericized using C++ templates, but only template instantiations can be exported to .winmd metadata (with some [[name mangling]]), unlike WinRT generics which preserve their genericity in the metadata. WinRT also provides a set of interfaces for generic [[Container (abstract data type)|containers]] that parallel those in the [[C++ Standard Library]], and languages provide some reciprocal (back-and-forth) conversion functions. The consumption of WinRT collections in .NET languages (e.g., C# and VB) and in JavaScript is more transparent than in C++, with automated mappings into their natural equivalents occurring behind the scenes. When authoring a WinRT component in a managed language, some extra, COM-style rules must be followed, e.g. .NET framework collection types cannot be declared as return types, but only the WinRT interfaces that they implement can be used at the component boundary. |
||
==== WinRT components ==== |
==== WinRT components ==== |
||
Line 44: | Line 45: | ||
=== Programming interfaces === |
=== Programming interfaces === |
||
Programs and libraries targeted for the WinRT runtime can be created and consumed from several platforms and programming languages. Notably [[C (programming language)|C]]/[[C++]] (either with language extensions offering first-class support for WinRT concepts, or with a lower-level template library allowing to write code in standard C++), .NET ([[C Sharp (programming language)|C#]] and [[Visual Basic .NET]] (VB.NET)) and [[JavaScript]]. This is made possible by the metadata. |
Programs and libraries targeted for the WinRT runtime can be created and consumed from several platforms and programming languages. Notably [[C (programming language)|C]]/[[C++]] (either with language extensions offering first-class support for WinRT concepts, or with a lower-level template library allowing to write code in standard C++), .NET ([[C Sharp (programming language)|C#]] and [[Visual Basic .NET]] (VB.NET)) and [[JavaScript]]. This is made possible by the metadata. In WinRT terminology, a [[language binding]] is termed a ''language projection.'' |
||
In WinRT terminology, a [[language binding]] is termed a ''language projection''. |
|||
==== C++ (C++/WinRT, Component Extensions, WRL) ==== |
==== C++ (C++/WinRT, Component Extensions, WRL) ==== |
||
Line 52: | Line 51: | ||
{{See also|C++/WinRT|C++/CX}} |
{{See also|C++/WinRT|C++/CX}} |
||
Standard C++ is a ''first-class citizen'' of the WinRT platform. As of Windows 10, version 1803, the Windows SDK contains C++/WinRT. C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide first-class access to the modern Windows API. With C++/WinRT, Windows Runtime APIs can be authored and consumed using any standards-compliant C++17 compiler. WinRT is a native platform and supports any native (and standard) C++ code, so that a C++ developer can reuse existing native C/C++ libraries. With C++/WinRT, there are no language extensions. |
|||
Prior to C++/WinRT being officially released in the Windows SDK, from October 2016,<ref>{{cite web|url=https://github.com/Microsoft/cppwinrt/releases/tag/v0.5 |title=Initial preview release of C++/WinRT |publisher=github.com |date=2016-10-05 |access-date=2016-10-05}}</ref> Microsoft offered on [[GitHub]] C++/WinRT.<ref>{{cite web|url=https://github.com/Microsoft/cppwinrt |title=C++/WinRT is a standard C++ language projection for the Windows Runtime |publisher=github.com |date=2016-09-14 |access-date=2016-09-14}}</ref> It does not rely on C++/CX code, with the result of producing smaller binaries and faster code.<ref>{{cite web|url=https://blogs.windows.com/buildingapps/2016/11/28/standard-c-windows-runtime-cwinrt/ |title=Standard C++ and the Windows Runtime (C++/WinRT) |publisher=blogs.windows.com |date=2016-11-28 |access-date=2016-11-28}}</ref> |
Prior to C++/WinRT being officially released in the Windows SDK, from October 2016,<ref>{{cite web|url=https://github.com/Microsoft/cppwinrt/releases/tag/v0.5 |title=Initial preview release of C++/WinRT |publisher=github.com |date=2016-10-05 |access-date=2016-10-05}}</ref> Microsoft offered on [[GitHub]] C++/WinRT.<ref>{{cite web|url=https://github.com/Microsoft/cppwinrt |title=C++/WinRT is a standard C++ language projection for the Windows Runtime |publisher=github.com |date=2016-09-14 |access-date=2016-09-14}}</ref> It does not rely on C++/CX code, with the result of producing smaller binaries and faster code.<ref>{{cite web|url=https://blogs.windows.com/buildingapps/2016/11/28/standard-c-windows-runtime-cwinrt/ |title=Standard C++ and the Windows Runtime (C++/WinRT) |publisher=blogs.windows.com |date=2016-11-28 |access-date=2016-11-28}}</ref> |
||
Line 65: | Line 64: | ||
{{See also|.NET Framework}} |
{{See also|.NET Framework}} |
||
The [[.NET Framework]] and the [[Common Language Runtime]] (CLR) are integrated into the WinRT as a subplatform. It has influenced and set the standards for the ecosystem through the metadata format and libraries. The CLR provides services like [[JIT-compilation]] code and [[Garbage collection (computer science)|garbage collection]]. WinRT applications using .NET languages use the new [[Windows Runtime XAML Framework]], and are primarily written in C#, VB.NET, and for the first time for XAML, with [[native code]] using C++/CX. Although not yet officially supported, programs can also be written in other .NET languages. |
The [[.NET Framework]] and the [[Common Language Runtime]] (CLR) are integrated into the WinRT as a subplatform. It has influenced and set the standards for the ecosystem through the metadata format and libraries. The CLR provides services like [[JIT-compilation]] code and [[Garbage collection (computer science)|garbage collection]]. WinRT applications using .NET languages use the new [[Windows Runtime XAML Framework]], and are primarily written in C#, VB.NET, and for the first time for XAML, with [[native code]] using C++/CX. Although not yet officially supported, programs can also be written in other .NET languages. With .NET 5, Microsoft removed the built-in WinRT support and instead created CsWinRT, a tool that generates interop code for accessing Windows Runtime APIs similar to how C++/WinRT works.<ref>{{Cite web|date=2020-09-22|title=CSWinRT: How to call Windows WinRT APIs from .NET5 applications|url=https://techcommunity.microsoft.com/t5/video-hub/cswinrt-how-to-call-windows-winrt-apis-from-net5-applications/m-p/1698639#M430|access-date=2021-06-14|website=TECHCOMMUNITY.MICROSOFT.COM|language=en}}</ref><ref>{{Citation|last=Mayberry|first=Michael|title=Building a .NET App with WinRT|date=2012|url=http://dx.doi.org/10.1007/978-1-4302-4585-8_3|work=WinRT Revealed|pages=29–46|place=Berkeley, CA|publisher=Apress|isbn=978-1-4302-4584-1|access-date=2021-06-14}}</ref> |
||
===== Limitations ===== |
===== Limitations ===== |
||
Line 77: | Line 76: | ||
==== Other languages ==== |
==== Other languages ==== |
||
Microsoft is in the process of projecting WinRT APIs to languages other than C++. One example is Rust/WinRT, an interface for programs written in [[Rust programming language|Rust]] to |
Microsoft is in the process of projecting WinRT APIs to languages other than C++. One example is Rust/WinRT, an interface for programs written in [[Rust programming language|Rust]] to consume and author WinRT APIs.<ref>{{cite web |title=microsoft/winrt-rs |url=https://github.com/microsoft/winrt-rs |website=GitHub }}</ref> Rust/WinRT is part of Project Reunion, a Microsoft effort to reconcile traditional Windows desktop and the UWP app model.<ref>{{cite web |title=microsoft/ProjectReunion: an evolution of the Windows developer platform that will make it more compatible, agile, modern and open. |url=https://github.com/microsoft/ProjectReunion|website=GitHub}}</ref> |
||
==== Bridges==== |
==== Bridges==== |
||
{{Expand section|date=August 2015}} |
{{Expand section|date=August 2015}} |
||
{{main|Universal Windows Platform#API bridges}} |
{{main|Universal Windows Platform#API bridges}} |
||
With the introduction of the [[Universal Windows Platform]] (UWP), |
With the introduction of the [[Universal Windows Platform]] (UWP), the platform has received many API bridges that allow programs originally developed for other platforms to be ported easily while taking advantage of UWP features. Microsoft has provided bridges for [[Android OS|Android]] (defunct since 2016), [[iOS]] ([[Cocoa Touch]]), [[Progressive Web Apps]], [[Silverlight]], as well as traditional Windows desktop apps (using MSIX packaging from Project Reunion). |
||
=== API === |
=== API === |
||
Line 132: | Line 131: | ||
;Asynchrony |
;Asynchrony |
||
: All WinRT methods are designed such that any method taking longer than 50 milliseconds is an async method. |
: All WinRT methods are designed such that any method taking longer than 50 milliseconds is an async method. |
||
: The established naming pattern to distinguish asynchronous methods is <code><Verb>[<Noun>]Async</code>. For the full runtime library, all methods that have a chance to last longer than 50 ms are implemented as asynchronous methods only. |
: The established naming pattern to distinguish asynchronous methods is <code><Verb>[<Noun>]Async</code>. For the full runtime library, all methods that have a chance to last longer than 50 ms are implemented as asynchronous methods only.Version history |
||
== Version history == |
|||
{{Expand section|date=August 2015}} |
|||
{| class="wikitable" |
|||
!Windows version |
|||
! |
|||
|- |
|||
|Windows 8 |
|||
|Windows Runtime |
|||
|- |
|||
|Windows 8.1 |
|||
| |
|||
|- |
|||
|Windows 10 |
|||
|[[Universal Windows Platform]] (UWP) |
|||
|} |
|||
== Windows Phone Runtime == |
== Windows Phone Runtime == |
||
[[Windows Phone 8.1]] uses a version of the Windows Runtime named the ''Windows Phone Runtime''. It enables developing applications in C# and VB.NET, and Windows Runtime components in C++/CX.<ref>{{cite web|date=July 21, 2014|title=Windows Phone API reference|url=https://msdn.microsoft.com/library/windows/apps/ff626516%28v=vs.105%29.aspx|website=Windows Phone API reference|publisher=[[Microsoft]]}}</ref> Although WP8 brought limited support, the platform did eventually converge with [[Windows 8.1]] in [[Windows Phone 8.1]]. |
|||
=== Windows Phone 8 === |
=== Windows Phone 8 === |
||
Line 180: | Line 163: | ||
[[Category:Windows APIs]] |
[[Category:Windows APIs]] |
||
[[Category:Windows technology]] |
[[Category:Windows technology]] |
||
[[Category:Application programming interfaces]] |
Revision as of 03:58, 14 June 2021
Other names | WinRT |
---|---|
Developer(s) | Microsoft |
Initial release | September 2011 |
Written in | C++ |
Engine | Component Object Model |
Operating system | Microsoft Windows |
Predecessor | Win32 API |
Type | Application binary interface, Application programming interface |
Website | msdn![]() |
Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012. It is implemented in C++ and officially supports development in C++C++ (via C++/WinRT, C++/CX or WRL), Rust/WinRT, Python/WinRT, JavaScript-TypeScript, and the managed code languages C# and Visual Basic .NET (VB.NET).
WinRT is not a runtime in a traditional sense but rather a language-independent application binary interface based on COM to allow APIs be consumed from multiple languages but it does provide certain services usually provided by a full blown runtime such as type activation.[1] Apps using the Windows Runtime may run inside a sandboxed environment to allow greater security and stability and can natively support both x86 and ARM.[2][3] WinRT components are designed with interoperability among multiple languages and APIs in mind, including native, managed and scripting languages. Built-in APIs provided by Windows which use the WinRT ABI are commonly known as WinRT APIs however anyone can use the WinRT ABI for their own APIs.
Technology
WinRT is implemented in the programming language C++[4] and is object-oriented by design.[4] Its underlying technology, the Windows API (Win32 API), is written mostly in the language C.[5] It is an unmanaged application binary interface based on Component Object Model (COM) that allows interfacing from multiple languages, as does COM. However, the API definitions are stored in .winmd
files, which are encoded in ECMA 335 metadata format, which .NET Framework also uses with a few modifications. For WinRT components implemented in native code, the metadata file only contains the definition of methods, classes, interfaces and enumerations and the implementation is provided in a separate DLL.[6][7][8] This common metadata format makes it easier to consume WinRT APIs from .NET apps with simpler syntax than P/Invoke.[9] [unreliable source?] Windows provides a set of built-in APIs which are built on the WinRT ABI which provide everything from the XAML UI framework and device access such as camera, microphone etc...
The previous C++/CX (Component Extensions) language, which borrows some C++/CLI syntax, was introduced for writing and consuming WinRT components with less glue code visible to the programmer, relative to classic COM programming in C++, and imposes fewer restrictions relative to C++/CLI on mixing types. The Component Extensions of C++/CX are recommended for use at the API-boundary only, not for other purposes.[10] Regular C++ (with COM-specific discipline) can also be used to program with WinRT components,[11] with the help of the Windows Runtime C++ Template Library (WRL), which is similar in purpose to what Active Template Library provides for COM.[12] In 2019, Microsoft deprecated C++/CX in favor of the C++/WinRT header library.[13]
Most WinRT applications run within a sandbox and need explicit user approval to access critical OS features and underlying hardware. By default, file access is restricted to several predetermined locations, such as the directories Documents or Pictures.[14]
WinRT applications are packaged in the .appx and later the .msix file format; based upon Open Packaging Conventions, it uses a ZIP format with added XML files.[15] WinRT applications are distributed mostly through an application store named Microsoft Store, where Windows apps (termed Windows Store apps) can be purchased and downloaded by users. WinRT apps can only be sideloaded from outside Windows Store on Windows 8 or RT systems that are part of a Windows domain, or equipped with a special activation key obtained from Microsoft.[16][17][18][19]These restrictions were lifted in the Windows 10 November Update, where users can freely sideload any app signed with a trusted certificate by enabling a setting.[20]
In a major departure from Win32 and similarly to .NET Framework 4.5, most APIs which are expected to take significant time to complete are implemented as asynchronous. When calling a Windows Runtime ABI, the task is started on another thread or process and returns immediately, freeing the app to perform other tasks while waiting for results.[21] The asynchronous model requires new programming language constructs. Each language provides their own way to consume asynchronous APIs. Parts of the built-in API needing asynchronous access include on-screen messages and dialogs, file access, Internet connectivity, sockets, streams, devices and services, and calendar, contacts and appointments.
Services
Metadata
The metadata describes the APIs written using the WinRT ABI. It defines a programming model that makes it possible to write object-oriented code that can be shared across programming languages, and enables services like reflection.
Herb Sutter, C++ expert at Microsoft, explained during his session on C++ at the 2011 Build conference that the WinRT metadata is in the same format as CLI metadata.[10] Native code (i.e., processor-specific machine code) cannot contain metadata, so it is stored in a separate metadata file that can be reflected like ordinary CLI assemblies.[22] Since it is the same format as CLI metadata, WinRT APIs can be used from managed CLI languages as if it was just a .NET API.
Type system
WinRT has a rich object-oriented class-based type system that is built on the metadata. It supports constructs with corresponding constructs in the .NET framework: classes, methods, properties, delegates, and events.
One of the major additions to WinRT relative to COM is the cross-application binary interface (ABI), .NET-style generics. Only interfaces and delegates can be generic, runtime classes and methods in them can't. Generic interfaces are also known as parameterized interfaces. In C++/CX, they are declared using the keyword generic
with a syntax very similar to that of keyword template
. WinRT classes (ref classes) can also be genericized using C++ templates, but only template instantiations can be exported to .winmd metadata (with some name mangling), unlike WinRT generics which preserve their genericity in the metadata. WinRT also provides a set of interfaces for generic containers that parallel those in the C++ Standard Library, and languages provide some reciprocal (back-and-forth) conversion functions. The consumption of WinRT collections in .NET languages (e.g., C# and VB) and in JavaScript is more transparent than in C++, with automated mappings into their natural equivalents occurring behind the scenes. When authoring a WinRT component in a managed language, some extra, COM-style rules must be followed, e.g. .NET framework collection types cannot be declared as return types, but only the WinRT interfaces that they implement can be used at the component boundary.
WinRT components
Classes that are compiled to target the WinRT are called WinRT components. They are classes that can be written in any supported language and for any supported platform. The key is the metadata. This metadata makes it possible to interface with the component from any other WinRT language. The runtime requires WinRT components that are built with .NET Framework to use the defined interface types or .NET type interfaces, which automatically map to the first named. Inheritance is as yet not supported in managed WinRT components, except for XAML classes.[23]
Programming interfaces
Programs and libraries targeted for the WinRT runtime can be created and consumed from several platforms and programming languages. Notably C/C++ (either with language extensions offering first-class support for WinRT concepts, or with a lower-level template library allowing to write code in standard C++), .NET (C# and Visual Basic .NET (VB.NET)) and JavaScript. This is made possible by the metadata. In WinRT terminology, a language binding is termed a language projection.
C++ (C++/WinRT, Component Extensions, WRL)
Standard C++ is a first-class citizen of the WinRT platform. As of Windows 10, version 1803, the Windows SDK contains C++/WinRT. C++/WinRT is an entirely standard modern C++17 language projection for Windows Runtime (WinRT) APIs, implemented as a header-file-based library, and designed to provide first-class access to the modern Windows API. With C++/WinRT, Windows Runtime APIs can be authored and consumed using any standards-compliant C++17 compiler. WinRT is a native platform and supports any native (and standard) C++ code, so that a C++ developer can reuse existing native C/C++ libraries. With C++/WinRT, there are no language extensions.
Prior to C++/WinRT being officially released in the Windows SDK, from October 2016,[24] Microsoft offered on GitHub C++/WinRT.[25] It does not rely on C++/CX code, with the result of producing smaller binaries and faster code.[26]
There are two other legacy options for using WinRT from C++: WRL, an ATL-style template library, and C++/CX (C++ with Component Extensions) which resembles C++/CLI.[27] Because of the internal consumption requirements at Microsoft, WRL is exception-free, meaning its return-value discipline is HRESULT-based just like that of COM.[28] C++/CX on the other hand wraps-up calls to WinRT with code that does error checking and throws exceptions as appropriate.[29]
C++/CX has several extensions that enable integration with the platform and its type system. The syntax resembles the one of C++/CLI although it produces native (although not standard) code and metadata that integrates with the runtime. For example, WinRT objects may be allocated with ref new
, which is the counterpart of gcnew
from C++/CLI. The hat operator ^
retains its meaning, however in the case where both the caller and callee are written in C++ and living in the same process, a hat reference is simply a pointer to a vptr to a virtual method table (vtable, VMT).[29]
Along with C++/CX, relative to traditional C++ COM programming, are partial classes, again inspired by .NET. These allow instance XAML code to be translated into C++ code by tools, and then combined with human-written code to produce the complete class while allowing clean separation of the machine-generated and human-edited parts of a class implementation into different files.
.NET
The .NET Framework and the Common Language Runtime (CLR) are integrated into the WinRT as a subplatform. It has influenced and set the standards for the ecosystem through the metadata format and libraries. The CLR provides services like JIT-compilation code and garbage collection. WinRT applications using .NET languages use the new Windows Runtime XAML Framework, and are primarily written in C#, VB.NET, and for the first time for XAML, with native code using C++/CX. Although not yet officially supported, programs can also be written in other .NET languages. With .NET 5, Microsoft removed the built-in WinRT support and instead created CsWinRT, a tool that generates interop code for accessing Windows Runtime APIs similar to how C++/WinRT works.[30][31]
Limitations
Classes defined in WinRT components that are built in managed .NET languages must be declared as sealed
, so they cannot be derived from. However, non-sealed WinRT classes defined elsewhere can be inherited from in .NET, their virtual methods overridden, and so on; but the inherited managed class must still be sealed.
Members that interface with another language must have a signature with WinRT types or a managed type that is convertible to these.[23]
JavaScript
WinRT applications can also be coded using HTML with JavaScript in code-behind, which are run using the Trident rendering engine and Chakra JavaScript engine, both of which are also used by Internet Explorer. When coding a WinRT app in JavaScript, its features are adapted to follow JavaScript naming conventions, and namespaces are also mapped to JavaScript objects.
Other languages
Microsoft is in the process of projecting WinRT APIs to languages other than C++. One example is Rust/WinRT, an interface for programs written in Rust to consume and author WinRT APIs.[32] Rust/WinRT is part of Project Reunion, a Microsoft effort to reconcile traditional Windows desktop and the UWP app model.[33]
Bridges
![]() | This section needs expansion. You can help by adding to it. (August 2015) |
With the introduction of the Universal Windows Platform (UWP), the platform has received many API bridges that allow programs originally developed for other platforms to be ported easily while taking advantage of UWP features. Microsoft has provided bridges for Android (defunct since 2016), iOS (Cocoa Touch), Progressive Web Apps, Silverlight, as well as traditional Windows desktop apps (using MSIX packaging from Project Reunion).
API
WinRT comes with an application programming interface (API) in the form of a class library that exposes the features of Windows 8 for the developer, like its immersive interface API. It is accessible and consumable from any supported language.
Runtime classes
The Windows Runtime classes is a set SDKs that provide access to all functionality from the XAML parser to the camera function. The SDKs are implemented as native C/C++ libraries (unmanaged).
Naming conventions
The naming conventions for the components (classes and other members) in the API are heavily influenced by the .NET naming conventions which uses camel case (specifically PascalCase). Microsoft recommends users to follow these rules in case where no others are given.
These conventions are projected differently in some languages, like JavaScript, which converts it to its conventions and the other way around. This is to give a native and consistent experience regardless of the programming language.
Restrictions and rules
Since Windows Runtime is projected to various languages, some restrictions on fundamental data types exist so as to host all such languages. Programmers must be careful with the behavior of those types when used with public access (for method parameters, method return values, properties, etc.).[34]
- Basic types
- In .NET languages and C++, a rich set of data types exists, representing various numerals.
- In JavaScript, a
Number
can only represent up to 53 bits of precision. - In WinRT, the only lacking numeral data type is 8-bit signed integer relative to .NET and C++. JavaScript developers must be careful when dealing with big numbers while coding for WinRT.
- Strings
- Strings are immutable in .NET and JavaScript, but mutable in C++.
- A null pointer passed as a string to WinRT by C++ is converted to an empty string
- In .Net, null being passed as a string to WinRT is converted to an empty string
- In JavaScript, null being passed as a string to WinRT is converted to a string with the word
null
. This is due to JavaScript's keywordnull
being represented as a null object. Similar results occur when passingundefined
to WinRT from JavaScript. - Structs
- In .NET and C++, structs are value types, and such a struct can contain any type in it.
- JavaScript does not directly support structs.
- In WinRT, use of structs is allowed only for containing types that have value semantics, including numerals, strings, and other structs. Pointers or interface references are disallowed.
- References
- In .NET, objects are passed by reference, whereas numerals and structs are passed by value.
- In C++, all types can be passed by reference or value.
- In WinRT, interfaces are passed by reference; all other types are passed by value.
- Arrays
- In .NET, C++, and JavaScript arrays are reference types.
- In WinRT, arrays are value types.
- Events
- In .NET and C++, clients subscribe to events using
+=
operator. - In JavaScript,
addEventListener
function or settingon<EventName>
property is used to subscribe to events. - In WinRT, all languages can use their own way to subscribe to events.
- Collections
- Some .NET collections map directly to WinRT collections.
- WinRT Vector type resembles arrays and the array syntax is used to consume them.
- WinRT Map type is a key/value pair collection, and is projected as Dictionary in .NET languages.
- Method overloading
- All WinRT languages (.NET, C++, JavaScript) support overloading on parameters
- .NET and C++ also support overloading on type.
- In WinRT, only parameter number is used for overloading.
- Asynchrony
- All WinRT methods are designed such that any method taking longer than 50 milliseconds is an async method.
- The established naming pattern to distinguish asynchronous methods is
<Verb>[<Noun>]Async
. For the full runtime library, all methods that have a chance to last longer than 50 ms are implemented as asynchronous methods only.Version history
Windows Phone Runtime
Windows Phone 8.1 uses a version of the Windows Runtime named the Windows Phone Runtime. It enables developing applications in C# and VB.NET, and Windows Runtime components in C++/CX.[35] Although WP8 brought limited support, the platform did eventually converge with Windows 8.1 in Windows Phone 8.1.
Windows Phone 8
Windows Phone 8 has limited support for developing and consuming Windows Runtime components through Windows Phone Runtime. Many of the Windows Runtime APIs in Windows 8 that handle core operating system functions have been ported to Windows Phone 8.[36] Support for developing native games using C++/CX and DirectX has been added, by request from the game development industry.
However, the Windows Phone XAML Framework is still based on the same Microsoft Silverlight framework, as in Windows Phone 7, for backward compatibility. Thus, as of 2016[update], XAML development is impossible in C++/CX. Development using either HTML5 or WinJS is unsupported on Windows Phone 8.
Windows Phone 8.1
Windows Runtime support on Windows Phone 8.1 converges with Windows 8.1. The release brings a full Windows Runtime API to the platform, including support for Windows Runtime XAML Framework, and language bindings for C++/CX, and HTML5-JavaScript. There is also a project type called Universal apps to enable apps to share code across 8.1 versions of Windows Phone and Windows.
The Windows Phone 8 Silverlight Framework has been updated.[when?] It can exploit some of the new features in the Windows Runtime.
Windows Phone Runtime uses the AppX package format from Windows 8, after formerly using Silverlight XAP.
See also
References
- ^ Zhang, Yi (2017-03-15). "Windows Runtime is not a Runtime". yizhang82’s blog. Retrieved 2021-06-14.
- ^ Avram, Abel (21 September 2011). "Design Details of the Windows Runtime". InfoQ.
- ^ Klug, Brian; Smith, Ryan (13 September 2011). "Microsoft Build: Windows 8, A Pre-Beta Preview". AnandTech.
- ^ a b Michael, Mayberry (2012). WinRT Revealed. New York City: Apress. p. 3. ISBN 978-1-4302-4585-8.
- ^ "Creating Win32 Applications (C++)". MSDN. Microsoft. Retrieved 12 January 2014.
- ^ "Windows Metadata (WinMD) files". API reference for UWP apps. Microsoft Docs. Retrieved 2019-07-20.
- ^ De Icaza, Miguel (15 September 2011). "WinRT demystified". Personal blog of Miguel de Icaza. Self-published. Retrieved 15 January 2014.
- ^ "WINMD Files Under the Hood". CodeProject. 2012-10-15. Retrieved 2021-06-14.
- ^ "What is the COM marshaling overhead in calling the WinRT API from C#?". MSDN forum. Self-published. 20 September 2011. Retrieved 15 January 2014.
- ^ a b "Using the Windows Runtime from C++ | Build2011 | Channel 9". Channel9.msdn.com. 2011-09-14. Retrieved 2012-04-24.
- ^ Sivakumar, Nish (2011-09-29). "Visual C++ and WinRT/Metro - Some fundamentals - CodeProject®". Codeproject.com. Retrieved 2012-04-24.
- ^ "Using the Windows Runtime from C++ | Build2011 | Channel 9". Channel9.msdn.com. 2011-09-14. Retrieved 2012-04-24.
- ^ "Introduction to C++/WinRT - Windows UWP applications". docs.microsoft.com. Microsoft.
- ^ lastnameholiu. "File access permissions - UWP applications". docs.microsoft.com. Retrieved 2020-08-08.
- ^ "Designing a simple and secure app package – APPX". Windows 8 app developer blog. Retrieved 30 December 2013.
- ^ "How to Add and Remove Apps". TechNet. Microsoft. 31 May 2012. Retrieved 4 October 2012.
To enable sideloading on a Windows 8 Enterprise computer that is not domain-joined or on any Windows® 8 Pro computer, you must use a sideloading product activation key. To enable sideloading on a Windows® RT device, you must use a sideloading product activation key. For more information about sideloading product activation keys, see Microsoft Volume Licensing.
- ^ "Windows 8: The Metro Mess". PC Magazine. Retrieved 8 September 2012.
- ^ "Microsoft now using 'Modern UI Style' to refer to Windows 8 'Metro Style' apps". Retrieved 10 August 2012.
- ^ "What's a Microsoft Store app?". Windows Dev Center. Retrieved 1 October 2012.
- ^ "What Is Sideloading & How To Sideload Apps On Windows 10? [DETAILS]". Silicophilic. 2019-07-27. Retrieved 2021-06-14.
- ^ "Asynchronous programming (Windows Store apps)". MSDN. Microsoft. Retrieved 12 January 2014.
- ^ ".NET Gets a New Lease of Life". Archived from the original on September 24, 2011. Retrieved September 16, 2011.
- ^ a b "Using the Windows Runtime from C# and Visual Basic | Build2011 | Channel 9". Channel9.msdn.com. 2011-09-14. Retrieved 2012-04-24.
- ^ "Initial preview release of C++/WinRT". github.com. 2016-10-05. Retrieved 2016-10-05.
- ^ "C++/WinRT is a standard C++ language projection for the Windows Runtime". github.com. 2016-09-14. Retrieved 2016-09-14.
- ^ "Standard C++ and the Windows Runtime (C++/WinRT)". blogs.windows.com. 2016-11-28. Retrieved 2016-11-28.
- ^ "Inside the C++/CX Design - Visual C++ Team Blog - Site Home - MSDN Blogs". Blogs.msdn.com. 2011-10-20. Retrieved 2012-04-24.
- ^ Charles (2011-10-26). "GoingNative 3: The C++/CX Episode with Marian Luparu | C9::GoingNative | Channel 9". Channel9.msdn.com. Retrieved 2012-04-24.
- ^ a b Under the covers with C++ for Metro style apps with Deon Brewis at //Build
- ^ "CSWinRT: How to call Windows WinRT APIs from .NET5 applications". TECHCOMMUNITY.MICROSOFT.COM. 2020-09-22. Retrieved 2021-06-14.
- ^ Mayberry, Michael (2012), "Building a .NET App with WinRT", WinRT Revealed, Berkeley, CA: Apress, pp. 29–46, ISBN 978-1-4302-4584-1, retrieved 2021-06-14
- ^ "microsoft/winrt-rs". GitHub.
- ^ "microsoft/ProjectReunion: an evolution of the Windows developer platform that will make it more compatible, agile, modern and open". GitHub.
- ^ "Ten Tips When Writing a Hybrid Language Metro style Application - Build2011 - Channel 9". Channel 9. Microsoft.
- ^ "Windows Phone API reference". Windows Phone API reference. Microsoft. July 21, 2014.
- ^ "Windows Phone Runtime API". microsoft.com. Microsoft.