4. Benefits of Windows Runtime
As you have learned, Windows Runtime is
a new modern API over Windows Core OS Services, and it is more natural
to use from many programming languages, including C++, C#, Visual Basic
(.NET), and HTML/JavaScript. This modernization allowed Windows Runtime
architects to rethink how a contemporary operating system should
support application development:
- Windows Runtime provides an easy access to hardware such as a
Global Positioning System (GPS) unit, sensors, camera, or other modern
hardware devices — with a few lines of code. Although, in the past, you
had to write a several dozen lines of code to create the first “Hello,
world” program in C with Windows 3.1, Windows Runtime enables you to
take a picture with the built-in camera in about five lines of code.
- Applications run in a security sandbox.
This means that only those operations are executed that are deemed safe
within the current security context. For example, if an application
wants to turn on the microphone, this operation is thought unsafe
unless the user explicitly confirms that he or she allows using the
microphone.
- The old Win32 API was a separate layer over the core operating
system services. Windows Runtime is an integral part of the operating
system tuned for developer experience. Windows Runtime is not only
easier to use than Win32, but it is more stable and has improved memory
management to allow less memory consumption and faster memory
management.
- Modern hardware devices and the always-responsive UI cannot work
without an asynchronous programming model. Windows Runtime supports
asynchrony natively.
5. What’s not in Windows Runtime
By now, you have learned that Windows
Runtime is the key component to developing Windows 8 style
applications. All services of the operating system exposed through
Windows Runtime can be consumed from C++, C#, Visual Basic, and
JavaScript. Before you put an equation sign between Windows 8 style
applications and Windows Runtime, you should know that Windows 8 style
applications can leverage other operating system components that are
not available in Windows Runtime.
Applications written in the C or C++ programming
languages are compiled directly to CPU-specific machine instructions
that can be directly executed on the CPU. These applications can
directly access the native operating system components responsible for
rendering the UI, controlling input devices, managing sensors,
communicating with the GPU, and much more. Most of these components may
add extra value to Windows 8 style applications. For example, game
programmers can leverage the high-performance graphics capabilities of
DirectX APIs, such as Direct2D, Direct3D, DirectWrite, XAudio2, and
XInput.
NOTE Microsoft DirectX is a
collection of multimedia and game APIs. These APIs eliminate several
additional layers between applications and the hardware hosting the
specific function to provide the high performance required by
multimedia and game applications. Direct2D is the two-dimensional
graphics API, and Direct3D is designed for three-dimensional graphics
game development. DirectWrite is a text-layout and glyph-rendering API
that was shipped with Windows Vista first, and is still available in
Windows 8.
When Microsoft set out to develop its
gaming console, the X was used as the basis of the name “Xbox” to
indicate that the console was based on DirectX technology.
These APIs provide a very thin layer between your
application and the hardware they access, and use low-level data
structures to move information to and from the app and the hardware.
Although services available through Windows Runtime are safe with
regard to UI responsibility and system stability, these APIs are tuned
for performance — requiring more control within your application.
Using C++, you can create Windows 8 style
applications that leverage DirectX API features. For example, you can
create great calligraphic texts with DirectWrite, as shown in Figure 9.
Although these components are not
available through Windows Runtime, and you can access them directly
only from C++, mechanisms in C# and Visual Basic utilize these APIs in
managed code.