The Windows Runtime Library

WinRT, distilled to its simplest definition, is a Windows API that sits directly on top of the core Windows 8 services. As such, it is actually a direct peer of the previous Win32 API. Microsoft invested in a new runtime library for a few different reasons. For one, Win32 APIs weren’t the easiest to access and develop against from a .NET perspective. The impedance mismatch between the .NET Framework surface and the Win32 API/COM surface made for sometimes confusing, and sometimes impossible, development tasks.

Figure 23.7 shows the traditional “layer cake” architecture diagram, clearly demonstrating where the WinRT sits in relationship to the other parts of the OS and the development platform.

Image

FIGURE 23.7 The WinRT architecture.

With WinRT, Microsoft has gone to great lengths to wrap all the underlying Windows behavior and surface functionality in a way that is a) straightforward for .NET developers to understand, and b) in many cases directly mimics or replicates the existing .NET Framework objects. This means no more P/Invoke or COM-related attributes in your code.

Here is a simple example. The following line of XAML code performs identical things when compiled against WinRT and the .NET Framework.

<Button Click="Button_Click_1" Content="OK" />

Conversely, if we were to set out to write a Hello, World! application in WinRT, we might be tempted to write this.

MessageBox.Show("Hello, World!");

That line of C# would work great in either a standard WPF application or a Windows Forms application. If you were to try to implement this using WinRT, however, you would quickly discover that WinRT doesn’t have a MessageBox class. It does, however, have a MessageDialog class.

MessageDialog dialog = new MessageDialog("Hello, World!");
Dialog.ShowAsync;

So, although the approach and syntax are familiar for .NET Framework developers, there is not a 100% match between .NET Framework classes and WinRT classes. Also note that the WinRT XAML stack has been rewritten without .NET, and you might find some differences with advanced features of the WPF version of XAML presented in Chapter 21, “Building WPF Applications.”


Note

WinRT, as shorthand for the Windows Runtime library, should not be confused with Windows RT. Windows RT was Microsoft’s product name for the version of Windows 8 designed to run on ARM-based devices (as opposed to Intel- or AMD-based machines). With few exceptions, the Windows RT operating system is only capable of running Windows Store applications.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset