Skip to main content

5 points developers should know about WinRT/Windows 8

imageMost of us already started developing for WinRT, so it make sense to have a better understanding of the run time. I am listing down few points with respect to WinRT, mainly from a developer’s perspective.

1 – WinRT is a new collection of COM objects, native to Windows

Here are some quick points about WinRT

  • WinRT is native, and all WinRT objects are unmanaged and use COM as the base.
  • WinRT objects implement IUnknown and ref counting. 
  • WinRT objects wraps a new XAML UI system, along with Win32 APIs. It consumes tons of Win32 APIs (Do dumpbin on a WinRT library) . The new set of XAML libraries are purely native, don’t confuse them with Silverlight or WPF though the terminologies remain same.
  • As WinRT is COM and hence it is more closer to the Operating system, it is easier to write language bindings (Projections) for WinRT.
  • A projection is a way of expressing WinRT in each language. More about this below
  • Just in case you havn’t perceived it yet, WinRT world is totally different than the managed .NET world.
  • WinRT libraries are built ground up using these new set of WinRT objects, and are kept in the Windows* namespaces. Eg. Windows.UI, Windows.Media, Windows.Networking, Windows.Security, Windows.Devices etc.

2 – WinRT is not exactly your mama’s COM

You don’t need to work with the crappy old  COM style, even while developing applications in C++. WinRT provides a higher level of abstraction, based on COM. Win RT implements multiple features on top of COM, including

  • A Subscriber/Publisher model implemented using .NET inspired Delegates and events. In ‘old’ COM, this was done using events/sinks
  • Parameterized interfaces or PInterfaces  (some what equivalent to generics), and this can be projected if the language supports them.
  • WinRT components don’t implement IDispatch

3 – WinRT can be accessed from multiple languages/platforms

WinRT itself is language neutral. Also, WinRT has got a language neutral type system. 

  • In some languages, you may even consume some WinRT types ‘as is’.
  • In some other languages (like C#), WinRT types may be mapped to equivalent language types. For example, in C#, WinRT’s IIterable<T> is mapped to IEnumerable<T> – where CLR will take care of the mapping.
  • Full list of WinRT <-> CLR mapped types table is here.

In short, you can ‘project’ WinRT to multiple languages. The language run time will take care of the Garbage collection implementation. All WinRT components implement IInspectible interface for projecting itself to other language environments.

4 – Though WinRT  is unmanaged, it has got Meta Data

You might be thinking, if WinRT is so unmanaged, how we can call into WinRT from other environments, especially from the managed world without old techniques like P/Invoke?. In fact, Windows Runtime libraries are exposed using API metadata stored in .winmd files. You could find the winmd metadata corresponding to the WinRT libraries.

  • The format used for exposing metadata is the same as what is used by the .NET framework or Ecma-335 spec (Secret : WinMD files follow the same format of CLR assemblies though they don’t have any IL. Winmd files are just the definitions of the API. The implementation, as discussed, may be managed).
  • The underlying binary contract makes it easy for you to access the Windows Runtime APIs directly in the development language you choose.

As the metadata format is similar to the .NET format, you can open a .winmd file in ILDASM and explore, like this.

image

5 – WinRT API has got language bindings projections

As mentioned, a projection is a way of expressing WinRT in a specific language.  You may also create WinRT components in one language, and may consume the same from another (because the metadata is available).

Presently, these are the projections available.

C++ Projections

Using the C++/CX (Component Extensions) which does compile time bindings and compiles the code to a native image. As WinRT is fully native, applications developed using C++ doesn’t need CLR/.NET to compile/run WinRT applications. C++/CX is a set of extensions from Microsoft for developing for WinRT (much like C++/CL was for developing CLR/.NET apps in C++).

C#/XAML

CLR is modified to support WinRT access from the managed world.

  • Now CLR can can map WinRT types when you use C# as the language.
  • When you create WinRT components in C# that can be used from other languages, you are further restricted to a minimal subset of C# (language features). 

When you develop for WinRT in C#/XAML, you’ll notice multiple things.

  • As WinRT applications are sandboxed, you don’t have access to a lot of .NET libraries and types like File I/O. Only a minimal set of .NET APIs targeting the metro profile will be exposed
  • You don’t have access to the synchronous versions of a number of methods. You need to leverage the asynchronous versions in those cases.
  • When CLR does the mapping of WinRT types to CLR types, the WinRT type definitions are made private by the CLR.  I may explain the actual mapping process in another post Winking smile
  • You can access WinRT XAML library, or can use the WebView as the front end when you use C# for your metro style apps.

JavaScript Projections

Javascript projections are probably the most abstract and highest level projections for developing WinRT applications. How ever, you can’t create WinRT Components in Javascript. Also, you can’t use WinRT’s XAML library in/from JavaScript as of now. How ever, the advantage is if you are using Javascript, you could also leverage the HTML5 features for developing your applications. You can use the WinJS scripts and CSS files from Microsoft to provide the ‘metro-style’ look and feel.

That is about WinRT for a good start.

Popular posts from this blog

Top 7 Coding Standards & Guideline Documents For C#/.NET Developers

Some time back, I collated a list of 7 Must Read, Free EBooks for .NET Developers, and a lot of people found it useful. So, I thought about putting together a list of Coding Standard guidelines/checklists for .NET /C# developers as well.As you may already know, it is easy to come up with a document - the key is in implementing these standards in your organization, through methods like internal trainings, Peer Reviews, Check in policies, Automated code review tools etc. You can have a look at FxCop and/or StyleCop for automating the review process to some extent, and can customize the rules based on your requirements.Anyway, here is a list of some good Coding Standard Documents. They are useful not just from a review perspective - going through these documents can definitely help you and me to iron out few hidden glitches we might have in the programming portion of our brain. So, here we go, the listing is not in any specific order.1 – IDesign C# Coding StandardsIDesign C# coding stand…

5 Awesome Learning Resources For Programmers (To help you and your kids to grow the geek neurons)

Happy New Year, this is my first post in 2012. I’ll be sharing few awesome learning resources I’ve bookmarked, and will be pointing out some specific computer/programming related courses I've found interesting from these resources.Also, thought about saving this blog post for my kids as well - instead of investing in these Child education schemes (though they are too small as of today, 2 years and 60 days respectively ). Anyway, personally my new year resolution is to see as much videos from this course collections (assuming I can find some free time in between my regular job && changing my babies diapers).1 – Khan AcademyAs I mentioned some time back, you and your kids are missing some thing huge if you havn’t heard about Khan Academy.  It is an awesome learning resource, especially if you want to re-visit your basics in Math, Science etc.With a library of over 2,600 videos covering everything from arithmetic to physics, finance, and history and 268 practice exercises, th…

Hack Raspberry Pi – How To Build Apps In C#, WinForms and ASP.NET Using Mono In Pi

Recently I was doing a bit of R&D related to finding a viable, low cost platform for client nodes. Obviously, I came across Raspberry Pi, and found the same extremely interesting. Now, the missing piece of the puzzle was how to get going using C# and .NET in the Pi. C# is a great language, and there are a lot of C# developers out there in the wild who are interested in the Pi.In this article, I’ll just document my findings so far, and will explain how develop using C# leveraging Mono in a Raspberry Pi. Also, we’ll see how to write few minimal Windows Forms & ASP.NET applications in the Pie as well.Step 1: What is Raspberry Pi?Raspberry Pi is an ARM/Linux box for just ~ $30. It was introduced with a vision to teach basic computer science in schools. How ever, it got a lot of attention from hackers all around the world, as it is an awesome low cost platform to hack and experiment cool ideas as Pi is almost a full fledged computer.  More About R-Pi From Wikipedia.The Raspberry Pi