Tuesday, October 04, 2011

WinRT and Metro style apps for Windows 8

Windows 8 WinRT platform is a significant change from previous versions of Windows based on Win32 and COM. In fact, many features of .NET are re-considered and re-designed: .NET was originally developed with codename COM+, but it is not based on COM; WinRT is also based on elements of COM, could call it COM++ :)

One of big challenges of using classic COM from C++ was verbose code.
A new solution for WinRT is modified C++ language, in addition to a native library.
There is also a "managed" .NET interface, used only form .NET languages.

Deep diving WinRT and Metro style apps for Windows 8

WinRT:

  • is the Windows runtime that exposes the functionality of the operating system in an object-oriented flavour.
  • It is not managed code and does not need. NET Framework
  • Uses the "Projections" that allow different languages ​​to interact with the operating system (C + +, C #, VB.Net, JavaScript)
  • Managed languages ​​sitting on WinRT still need the CLR. The .Net Framework included in Windows 8 is version 4.5
  • WinRT is built with COM technology and keep all relevant mechanisms (IUnknown, AddRef / Release, Apartment for threading models, the STA message pump to handle).
  • WinRT simplifies many of the old COM concepts. For example it removes connection points and IDispatch to allow dynamic languages ​​to interact with it.
  • The WinRT type system is small but larger than the COM. For example, BSTR no longer exists but, for example, the string has a memory layout similar to the one used by the CLR. This avoids the copies during marshalling. WinRT can expose the memory of the string to both managed and native code without performance penalties.
  • Among the changes in the type system there are the collection (including observable type) that are constructed / mapped by the projection automatically.
  • The projection of C++ directly map to the structures compatible with the STL (Standard Template Library).
  • Projections in WinRT are customized language-by-language and allow for the best performances.
  • You can write extensions to expose custom native code to applications using WinRT. But these extensions are private to that application and cannot be shared (no regsvr32)
  • Metro Contracts are exposed as COM interfaces, and most developers will never need to go down to level COM interface in order to use them
    At the lowest level there is WinRL, a C + + library used by the Windows team to build anything that exposes WinRT. It is believed that no one needs it (except myself of course)
  • WinRT versioning is based on the concepts of COM and allow evolving the interfaces in future versions of Windows.

    The Framework.NET:

  • It is useful to those who need the CLR benefits (garbage collection, etc..) And therefore will be used in C # and VB.NET
  • It is not essential and therefore JavaScript and C + + does not use it.
    Many libraries (BCL Winform, and everything he does I / O on video disk and so on) are not used by Metro. Applications must use specific WinRT functions. For example everything related to XAML (Metro-style) has been rewritten in native code.
  • There is a new XAML interpreter written in native code that maps XAML controls to Metro native controls
  • In the same way (for those who knows PhoneGap) html5 tags are mapped to native controls WinRT
  • XAML and HTML5 are peers, interchangeable and sit on the graphics engine (based on DirectX) applications that render Metro
  • No comments: