SlideShare a Scribd company logo
Programming Windows 8 With WinRT



                                             Rainer Stropek
                                             software architects gmbh




WinRT                                Mail
                                     Web
                                   Twitter
                                             rainer@timecockpit.com
                                             http://www.timecockpit.com
                                             @rstropek


The Start Of A New Era
                                             Saves the day.
Agenda



                                            What's WinRT?
                                            Windows Runtime (WinRT) is the
                                             basic technology that enables
                                             Windows 8.

                                            What is WinRT from a developer's
                                             standpoint?

                                            Is it really revolutionary new?
                                               What has changed? Why was
                                               change necessary?

                                            This session will be a technical
                                              deep dive into WinRT. It will not
                                              be a design or marketing
Windows reimagined                            session for Windows 8.
Metro-Design, Fast And Fluid, Touch, etc.
The Early Days…



                                                                        Before .NET…
                                                                        … every language had it's own
                                                                          compiler/interpreter, runtime
                                                                          environment, libraries, etc.
      Compiler            Compiler/Interpreter   Compiler/Interpreter


                                                                        This caused a lot of problems:

                                                                         Expensive to implement.

                                                                         How can they work together?

                                                                         How can one benefit from
                                                                          innovation happening in
                                                                          another island?
The World Before .NET…                                                  And many, many more.
…consisted of a lot of islands
The Early Days…



                                                                   COM…
                                                                   … introduced a binary interface
                                                                     for interoperable components.
                                                                     This opened a whole new world
      Compiler       Compiler/Interpreter   Compiler/Interpreter
                                                                     on the Windows platform:

                                                                    Cross-language component
                                                                     libraries.

                                                                    Rich application integration
                                                                     became possible – can you
                                                                     remember OLE?

                                                                    Even richer component
                                                                     technologies appeared – can
COM                                                                  you remember
Component Object Model                                               COM+, DCOM, or VBA?
Problems
 What Was Wrong With COM?

 Some    design flaws
 Can you remember the "DLL Hell"?
 Not really ready for the upcoming internet.

 COM    was no native part of the programming languages
 Inside a component you could use all language features.
 You had to write separate COM wrapper (e.g. map your types to COM's type system).
 Etc.
Problems
 And Finally…

 There   was this new language "Java"
 More productive and robust than e.g. C++.
 Built for a component-oriented world from day one.
 Platform independent.
 The next big thing?
.NET Appears…



                                                                        The .NET Revolution
Compiler
                                                                        Let's introduce a common
                                                                        language runtime with a class
                                                                        library and a language that can
                                                        Still
                                               important, someone
                                                                        compete with Java.
                                                has to build all this
                                                                         Building languages will be
                                                                          easier.
                                                                         Strong cross-language
                                                                          interoperability.
                                                                         Many languages benefit from
                                                                          the world-class, internet-ready
                                                                          class library.
 .NET = CLR + Library                                                    Make the CLR a standard and
 Common Language Runtime + .NET Framework Class Library                   become platform independent.
.NET – A Big Success!
 Today    dozens of languages are based on CLR
  We even have a DLR for dynamic languages like Python, Ruby and JavaScript.

 In   various products (hosts) and on multiple platforms
  CLR and C# are standards, somewhat platform independent (e.g. Mono, Silverlight).

 .NET   Framework Class Library
  One of the most complete frameworks on the market today.
  Big success factor for the .NET platform.
.NET For Everybody!
 Well…

 Huge    C++ Codebase
 PInvoke and COM Interop are ok but definitively no perfect solution.

 Unmanaged         code is important in some cases
 Games, compute-intensive calculations, etc.

 …and    than there is the browser
 JavaScript rules the web.
10 Year After The Rise Of .NET…



                                                           Limits Of .NET?
                                                            .NET Library often just a thin
                                                             wrapper around OS services.

                                                            (Unmanaged) C++ is still very
                                                             important, cannot benefit from
                                                             .NET Class Library (e.g. XAML).
                                                            JavaScript has become popular;
                                                             de-facto standard for platform
                                                             independence.
                                                            .NET Class Library needs some
                                                             redesign.

C++ And JavaScript                                         WinRT is for the new world of
C++ is still strong and JavaScript is the new big player   touch, tablets, and language
                                                           interoperability.
Access Native Code From .NET


[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindow")
]                                                                 PInvoke
static extern int capCreateCaptureWindow(
  string lpszWindowName, int dwStyle,                             Platform Invoke.
  int X, int Y, int nWidth, int nHeight,
                                                                  Import functions from
  int hwndParent, int nID);
                                                                    unmanaged libraries in .NET.
[DllImport("avicap32.dll")]                                       See MSDN for details.
static extern bool capGetDriverDescription(
  int wDriverIndex,
  [MarshalAs(UnmanagedType.LPTStr)] ref string lpszName,
  int cbName,
  [MarshalAs(UnmanagedType.LPTStr)] ref string lpszVer,
  int cbVer);
Access Native Code From .NET



                                                                              COM Interop
                                                                              Access COM objects from .NET

                                                                              Simplified in latest versions of
                                                                                .NET, still it does not feel
                                                                                "natural" to .NET developers.

                                                                              See MSDN for details.
//000013: var x = new XmlDocument();
 IL_0001: newobj
            instance void [System.Xml]System.Xml.XmlDocument::.ctor()


//000014: var y = new MyComObjectLib.MyClass();
 IL_0007: ldstr    "F61ED984-6153-486D-8392-303545E63C2D"
 IL_000c: newobj   instance void [mscorlib]System.Guid::.ctor(string)
 IL_0011: call     class [mscorlib]System.Type
   [mscorlib]System.Type::GetTypeFromCLSID(valuetype [mscorlib]System.Guid)
 IL_0016: call     object [mscorlib]System.Activator::CreateInstance([...])
 IL_001b: castclass MyComObjectLib.MyClass
From .NET To WinRT
 Combine        what's great in COM and .NET
  Binary interface for language interoperability.
  Metadata management of .NET.

 "New     COM" as a natural part of all languages/platforms
  .NET, C++, and JavaScript; maybe others will join the party, too.

 Build   a new class library on the new runtime
  Cleanup the library compared to .NET (e.g. async rules, dependencies, etc.)

 Do   not enforce managed code
The Windows 8 Platform



                                                    WinRT is…
                                                    … underlying infrastructure of
                                                      metro-style apps in Windows 8.


                                                     Binary interface for
                                                      interoperability (based on
                                                      COM).

                                                     Language projection layer for
                                                      .NET languages, C++ and
                                                      JavaScript.

                                                     Class library targeted at
                                                      development of metro-style
WinRT                                                 apps.
Windows Runtime – The Common Runtime Of Windows 8
The Windows 8 Platform



                                                    WinRT is…
                                                     secure runtime environment
                                                      which is the basis for the
                                                      upcoming Windows Store.


                                                    And a lot of other things that we
                                                    cannot cover here because of the
                                                    limited time.




WinRT
Windows Runtime – The Common Runtime Of Windows 8
The Windows 8 Platform



                                              Projection Means…
                                              … you can stick to naming
                                                conventions you are used to
                                                (e.g. camelCasing in
                                                JavaScript, PascalCasing in C#).

                                              … you can write WinRT
                                                components and your compiler
                                                will generate the necessary
                                                infrastructure (e.g. interfaces)

                                              … ref counting is automatically
                                                done behind the scenes.


Language Projection Layer
Because WinRT should feel "natural" to you.
The Windows 8 Platform



                                              Projection Means…
                                              … COM's interface-based logic is
                                                translated into namespaces and
                                                classes in the OO world.




Language Projection Layer
Because WinRT should feel "natural" to you.
Language Projection Layer


// Note that all parameters are passed as "hat pointers" (^). Hat
// pointers are pointers to WinRT objects. The pointer is           C++/CX
// automatically reference counted (COM’s IUnknown.AddRef and
// IUnknown.Release methods).                                       Extends the C++ syntax to make it
void OnShowMsgBoxWithCx(                                              easier to consume and write
  Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^eventArgs)      WinRT components.
{
  // Note that we create the new instance of the WinRT component    In this sample RoutedEventArgs
  // "MessageDialog" using "ref new" instead of new. This is           and MessageDialog are no
  // necessary to retrieve a handle to the instance and let            C++ classes, they are WinRT
  // WinRT do the reference counting.                                  (=COM) objects.
  auto msgBox = ref new Windows::UI::Popups::MessageDialog(
     "Hello World!");
  msgBox->ShowAsync();
                                                                    Quite similar to C#, isn't it?
}
Language Projection Layer


namespace MyApplication
{
                                                       C++/CX
  // Note that this class is defined as a ref class.
  // It becomes a WinRT component.                     Extends the C++ syntax to make it
  public ref class BlankPage sealed
                                                         easier to consume and write
  {
                                                         WinRT components.
    public:                                            In this sample RoutedEventArgs
      BlankPage();                                        and MessageDialog are no
    protected:                                            C++ classes, they are WinRT
      virtual void OnNavigatedTo(                         (=COM) objects.
         NavigationEventArgs^ e) override;
    private:
      void OnShowMsgBoxWithCx(
         Object ^sender, RoutedEventArgs ^eventArgs)
    { … }
  }
}
Language Projection Layer



Windows::UI::Popups::MessageDialog msgBox(
  "Hello World!");
                                             C++, WRL
msgBox.ShowAsync();                          It is possible to consume and
                                                 write WinRT components in
                                                 plain C++.

                                             You can even do it without any
                                               library support (not
                                               recommended).

                                             If you need to use plain C++
                                                instead of C++/CX use the
                                                Windows Runtime Library
                                                (WRL).


                                             These two lines of C++/CX code
                                               become…
Language Projection Layer



                                                                                   C++, WRL
void BlankPage::OnShowMsgBoxWrl(
  Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^eventArgs) {
  const wchar_t *msgBoxClassName = L"Windows.UI.Popups.MessageDialog";
  const wchar_t *helloWorldMessage = L"Hello World!";
  HSTRING hString, hWelcomeString;                                                 … many lines of code in plain C++
                                                                                     with WRL.
  auto hr = ::WindowsCreateString(msgBoxClassName,
    static_cast<UINT32>(::wcslen(msgBoxClassName)), &hString);
  if (SUCCEEDED(hr)) {
    Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialogFactory>        However, this example shows us
                                                                                     that at the very bottom WinRT…
      factory;
    hr = Windows::Foundation::GetActivationFactory(hString, &factory);
    if (SUCCEEDED(hr)) {
      hr = ::WindowsCreateString(helloWorldMessage,                                 is based on COM.
        static_cast<UINT32>(::wcslen(helloWorldMessage)), &hWelcomeString);

                                                                                    is exception-free (exceptions
      if (SUCCEEDED(hr)) {
        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialog> dialog;
        hr = factory->Create(hWelcomeString, &dialog);                               are introduced by the language
                                                                                     projection layer).
        if(SUCCEEDED(hr)) {
          Microsoft::WRL::ComPtr<
            __FIAsyncOperation_1_Windows__CUI__CPopups__CIUICommand> command;
          hr = dialog->ShowAsync(&command);                                         has it's own type system.
        }

                                                                                    etc.
        ::WindowsDeleteString(hWelcomeString);
      }
    }
    ::WindowsDeleteString(hString);
  }
}
Language Projection Layer



                                                            WinRT And .NET
                                                            C# and VB can consume WinRT
                                                              components as if they were
                                                              native .NET classes.

                                                            Even IL knows about the WinRT. It
.assembly extern System.Runtime {                             is deeply integrated into the
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                .NET platform.
  .ver 4:0:0:0
}
.assembly extern windowsruntime Windows {
  .ver 255:255:255:255
}
[...]
//000008: var x = new Windows.Data.Xml.Dom.XmlDocument();
  IL_0001: newobj instance void
    [Windows]Windows.Data.Xml.Dom.XmlDocument::.ctor()
Language Projection Layer



                              WinRT And .NET
                              While writing a COM component
                               in C#/VS 2010 was complex and
                               a lot of work…




COM Component In C#/VS 2010
A Lot Of Manual Coding…
Language Projection Layer



                                                       WinRT And .NET
                                                       … it is easy with the next version
                                                         of C# and VS.

                                                       If you follow some basic rules the
                                                          compiler will generate the
                                                          necessary infrastructure for you.

                                                       For details see MSDN.




WinRT Component In VS11
Very Simple With Some Limitations You Have To Follow
Language Projection Layer




Language Interop From C# To JavaScript Via WinRT
Note The Automatic Changes Of Casing…
So What?
 If You Are A .NET Developer…

 You   may ask yourself why you need something new
 Why didn't the other guys simply join your .NET platform?

 You   will continue to use the CLR.
 It is your bridge to seamless integration with WinRT.

 Access    OS services directly using WinRT
 No wrappers around Windows API any more.
 The parts of the .NET class library you will use will shrink.
So What?
 If You Are A C++ Developer…

 Welcome      to the world of XAML!
 You do not need to be jealous any more because the .NET guys have WPF ;-)
 Freely combine e.g. Direct3D with XAML-based UI parts.

 You   can easily program WinRT with C++/CX
 If you want/need to you can stick to ISO C++ by using WRL.

 Language      interop with .NET and JavaScript
 Share components with .NET and JavaScript developers.
So What?
  If You Are A JavaScript Developer…

 Use     your existing skillset to write apps for Windows
  You can enter the upcoming Windows Store.

 Visit   my next session about WinRT and JavaScript
Programming Windows 8 With WinRT



                                             Rainer Stropek
                                             software architects gmbh



                                     Mail    rainer@timecockpit.com

Q&A                                  Web
                                   Twitter
                                             http://www.timecockpit.com
                                             @rstropek


Thank You For Coming.
                                             Saves the day.

More Related Content

PPTX
Deep Dive into WinRT
PPTX
C++ in windows phone apps
PPTX
C++ in Windows Phone Apps - Overview
PPTX
App windows phone in c++
PPTX
Overview of .Net Framework 4.5
PPT
Dotnet framework
PPT
Introduction to .NET Framework
DOCX
The seven pillars of aspnet
Deep Dive into WinRT
C++ in windows phone apps
C++ in Windows Phone Apps - Overview
App windows phone in c++
Overview of .Net Framework 4.5
Dotnet framework
Introduction to .NET Framework
The seven pillars of aspnet

What's hot (18)

PPTX
.Net framework
PPTX
Java vs .net
PPTX
.NET Framework 4.0 – Changes & Benefits
PPTX
.net CLR
PPTX
Evolution of .net frame work
PPTX
Presentation1
PPT
Net framework
PPTX
Java Programming (M&M)
PPT
Synapse india reviews sharing asp.net
PDF
Droidcon 2011: Mosync mobile framework, Stefan Sels, Tronicum
PPT
SynapseIndia dotnet development framework
DOCX
Vb.net class notes
PPTX
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
PPTX
02 intro to programming in .net (part 2)
PDF
PPT
Asp dot net
PPT
PPT
test2PPT
.Net framework
Java vs .net
.NET Framework 4.0 – Changes & Benefits
.net CLR
Evolution of .net frame work
Presentation1
Net framework
Java Programming (M&M)
Synapse india reviews sharing asp.net
Droidcon 2011: Mosync mobile framework, Stefan Sels, Tronicum
SynapseIndia dotnet development framework
Vb.net class notes
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
02 intro to programming in .net (part 2)
Asp dot net
test2PPT
Ad

Similar to Programming With WinRT And Windows8 (20)

PDF
ITCamp 2012 - Raffaele Rialdi - Introduction to WinRT
PPTX
A Developer's View of Windows 8
PPTX
Windows 8 for .NET Developers
PPTX
PPTX
Windows 8 and the cloud a match made in heaven
PDF
Marlabs - MarlaBuzz November
PPTX
Radu vunvulea building and testing windows 8 metro style applications using ...
PPTX
Introduction to .NET with C# @ university of wayamba
PDF
C++Builder 2010 Datasheet
PDF
Build Windows Applications Fast | Delphi Features Matrix
PPT
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
PDF
Lang Net
PDF
Seaside Status Message
PDF
Seaside News
PDF
Windows 8 Development Stack
PPTX
Geek a-paloozaaa metro-xaml_appdev
PDF
Programming Languages and Software Construction
PPTX
Wired2Win Webinar: Windows8 Mobile App Development
PPTX
Win8 architecture for developers
PPTX
Metro Style Apps - Whats there for Developers
ITCamp 2012 - Raffaele Rialdi - Introduction to WinRT
A Developer's View of Windows 8
Windows 8 for .NET Developers
Windows 8 and the cloud a match made in heaven
Marlabs - MarlaBuzz November
Radu vunvulea building and testing windows 8 metro style applications using ...
Introduction to .NET with C# @ university of wayamba
C++Builder 2010 Datasheet
Build Windows Applications Fast | Delphi Features Matrix
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Lang Net
Seaside Status Message
Seaside News
Windows 8 Development Stack
Geek a-paloozaaa metro-xaml_appdev
Programming Languages and Software Construction
Wired2Win Webinar: Windows8 Mobile App Development
Win8 architecture for developers
Metro Style Apps - Whats there for Developers
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm

Programming With WinRT And Windows8

  • 1. Programming Windows 8 With WinRT Rainer Stropek software architects gmbh WinRT Mail Web Twitter rainer@timecockpit.com http://www.timecockpit.com @rstropek The Start Of A New Era Saves the day.
  • 2. Agenda What's WinRT? Windows Runtime (WinRT) is the basic technology that enables Windows 8. What is WinRT from a developer's standpoint? Is it really revolutionary new? What has changed? Why was change necessary? This session will be a technical deep dive into WinRT. It will not be a design or marketing Windows reimagined session for Windows 8. Metro-Design, Fast And Fluid, Touch, etc.
  • 3. The Early Days… Before .NET… … every language had it's own compiler/interpreter, runtime environment, libraries, etc. Compiler Compiler/Interpreter Compiler/Interpreter This caused a lot of problems:  Expensive to implement.  How can they work together?  How can one benefit from innovation happening in another island? The World Before .NET… And many, many more. …consisted of a lot of islands
  • 4. The Early Days… COM… … introduced a binary interface for interoperable components. This opened a whole new world Compiler Compiler/Interpreter Compiler/Interpreter on the Windows platform:  Cross-language component libraries.  Rich application integration became possible – can you remember OLE?  Even richer component technologies appeared – can COM you remember Component Object Model COM+, DCOM, or VBA?
  • 5. Problems What Was Wrong With COM?  Some design flaws Can you remember the "DLL Hell"? Not really ready for the upcoming internet.  COM was no native part of the programming languages Inside a component you could use all language features. You had to write separate COM wrapper (e.g. map your types to COM's type system). Etc.
  • 6. Problems And Finally…  There was this new language "Java" More productive and robust than e.g. C++. Built for a component-oriented world from day one. Platform independent. The next big thing?
  • 7. .NET Appears… The .NET Revolution Compiler Let's introduce a common language runtime with a class library and a language that can Still important, someone compete with Java. has to build all this  Building languages will be easier.  Strong cross-language interoperability.  Many languages benefit from the world-class, internet-ready class library. .NET = CLR + Library  Make the CLR a standard and Common Language Runtime + .NET Framework Class Library become platform independent.
  • 8. .NET – A Big Success!  Today dozens of languages are based on CLR We even have a DLR for dynamic languages like Python, Ruby and JavaScript.  In various products (hosts) and on multiple platforms CLR and C# are standards, somewhat platform independent (e.g. Mono, Silverlight).  .NET Framework Class Library One of the most complete frameworks on the market today. Big success factor for the .NET platform.
  • 9. .NET For Everybody! Well…  Huge C++ Codebase PInvoke and COM Interop are ok but definitively no perfect solution.  Unmanaged code is important in some cases Games, compute-intensive calculations, etc.  …and than there is the browser JavaScript rules the web.
  • 10. 10 Year After The Rise Of .NET… Limits Of .NET?  .NET Library often just a thin wrapper around OS services.  (Unmanaged) C++ is still very important, cannot benefit from .NET Class Library (e.g. XAML).  JavaScript has become popular; de-facto standard for platform independence.  .NET Class Library needs some redesign. C++ And JavaScript WinRT is for the new world of C++ is still strong and JavaScript is the new big player touch, tablets, and language interoperability.
  • 11. Access Native Code From .NET [DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindow") ] PInvoke static extern int capCreateCaptureWindow( string lpszWindowName, int dwStyle, Platform Invoke. int X, int Y, int nWidth, int nHeight, Import functions from int hwndParent, int nID); unmanaged libraries in .NET. [DllImport("avicap32.dll")] See MSDN for details. static extern bool capGetDriverDescription( int wDriverIndex, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszVer, int cbVer);
  • 12. Access Native Code From .NET COM Interop Access COM objects from .NET Simplified in latest versions of .NET, still it does not feel "natural" to .NET developers. See MSDN for details. //000013: var x = new XmlDocument(); IL_0001: newobj instance void [System.Xml]System.Xml.XmlDocument::.ctor() //000014: var y = new MyComObjectLib.MyClass(); IL_0007: ldstr "F61ED984-6153-486D-8392-303545E63C2D" IL_000c: newobj instance void [mscorlib]System.Guid::.ctor(string) IL_0011: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromCLSID(valuetype [mscorlib]System.Guid) IL_0016: call object [mscorlib]System.Activator::CreateInstance([...]) IL_001b: castclass MyComObjectLib.MyClass
  • 13. From .NET To WinRT  Combine what's great in COM and .NET Binary interface for language interoperability. Metadata management of .NET.  "New COM" as a natural part of all languages/platforms .NET, C++, and JavaScript; maybe others will join the party, too.  Build a new class library on the new runtime Cleanup the library compared to .NET (e.g. async rules, dependencies, etc.)  Do not enforce managed code
  • 14. The Windows 8 Platform WinRT is… … underlying infrastructure of metro-style apps in Windows 8.  Binary interface for interoperability (based on COM).  Language projection layer for .NET languages, C++ and JavaScript.  Class library targeted at development of metro-style WinRT apps. Windows Runtime – The Common Runtime Of Windows 8
  • 15. The Windows 8 Platform WinRT is…  secure runtime environment which is the basis for the upcoming Windows Store. And a lot of other things that we cannot cover here because of the limited time. WinRT Windows Runtime – The Common Runtime Of Windows 8
  • 16. The Windows 8 Platform Projection Means… … you can stick to naming conventions you are used to (e.g. camelCasing in JavaScript, PascalCasing in C#). … you can write WinRT components and your compiler will generate the necessary infrastructure (e.g. interfaces) … ref counting is automatically done behind the scenes. Language Projection Layer Because WinRT should feel "natural" to you.
  • 17. The Windows 8 Platform Projection Means… … COM's interface-based logic is translated into namespaces and classes in the OO world. Language Projection Layer Because WinRT should feel "natural" to you.
  • 18. Language Projection Layer // Note that all parameters are passed as "hat pointers" (^). Hat // pointers are pointers to WinRT objects. The pointer is C++/CX // automatically reference counted (COM’s IUnknown.AddRef and // IUnknown.Release methods). Extends the C++ syntax to make it void OnShowMsgBoxWithCx( easier to consume and write Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^eventArgs) WinRT components. { // Note that we create the new instance of the WinRT component In this sample RoutedEventArgs // "MessageDialog" using "ref new" instead of new. This is and MessageDialog are no // necessary to retrieve a handle to the instance and let C++ classes, they are WinRT // WinRT do the reference counting. (=COM) objects. auto msgBox = ref new Windows::UI::Popups::MessageDialog( "Hello World!"); msgBox->ShowAsync(); Quite similar to C#, isn't it? }
  • 19. Language Projection Layer namespace MyApplication { C++/CX // Note that this class is defined as a ref class. // It becomes a WinRT component. Extends the C++ syntax to make it public ref class BlankPage sealed easier to consume and write { WinRT components. public: In this sample RoutedEventArgs BlankPage(); and MessageDialog are no protected: C++ classes, they are WinRT virtual void OnNavigatedTo( (=COM) objects. NavigationEventArgs^ e) override; private: void OnShowMsgBoxWithCx( Object ^sender, RoutedEventArgs ^eventArgs) { … } } }
  • 20. Language Projection Layer Windows::UI::Popups::MessageDialog msgBox( "Hello World!"); C++, WRL msgBox.ShowAsync(); It is possible to consume and write WinRT components in plain C++. You can even do it without any library support (not recommended). If you need to use plain C++ instead of C++/CX use the Windows Runtime Library (WRL). These two lines of C++/CX code become…
  • 21. Language Projection Layer C++, WRL void BlankPage::OnShowMsgBoxWrl( Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^eventArgs) { const wchar_t *msgBoxClassName = L"Windows.UI.Popups.MessageDialog"; const wchar_t *helloWorldMessage = L"Hello World!"; HSTRING hString, hWelcomeString; … many lines of code in plain C++ with WRL. auto hr = ::WindowsCreateString(msgBoxClassName, static_cast<UINT32>(::wcslen(msgBoxClassName)), &hString); if (SUCCEEDED(hr)) { Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialogFactory> However, this example shows us that at the very bottom WinRT… factory; hr = Windows::Foundation::GetActivationFactory(hString, &factory); if (SUCCEEDED(hr)) { hr = ::WindowsCreateString(helloWorldMessage,  is based on COM. static_cast<UINT32>(::wcslen(helloWorldMessage)), &hWelcomeString);  is exception-free (exceptions if (SUCCEEDED(hr)) { Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialog> dialog; hr = factory->Create(hWelcomeString, &dialog); are introduced by the language projection layer). if(SUCCEEDED(hr)) { Microsoft::WRL::ComPtr< __FIAsyncOperation_1_Windows__CUI__CPopups__CIUICommand> command; hr = dialog->ShowAsync(&command);  has it's own type system. }  etc. ::WindowsDeleteString(hWelcomeString); } } ::WindowsDeleteString(hString); } }
  • 22. Language Projection Layer WinRT And .NET C# and VB can consume WinRT components as if they were native .NET classes. Even IL knows about the WinRT. It .assembly extern System.Runtime { is deeply integrated into the .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) .NET platform. .ver 4:0:0:0 } .assembly extern windowsruntime Windows { .ver 255:255:255:255 } [...] //000008: var x = new Windows.Data.Xml.Dom.XmlDocument(); IL_0001: newobj instance void [Windows]Windows.Data.Xml.Dom.XmlDocument::.ctor()
  • 23. Language Projection Layer WinRT And .NET While writing a COM component in C#/VS 2010 was complex and a lot of work… COM Component In C#/VS 2010 A Lot Of Manual Coding…
  • 24. Language Projection Layer WinRT And .NET … it is easy with the next version of C# and VS. If you follow some basic rules the compiler will generate the necessary infrastructure for you. For details see MSDN. WinRT Component In VS11 Very Simple With Some Limitations You Have To Follow
  • 25. Language Projection Layer Language Interop From C# To JavaScript Via WinRT Note The Automatic Changes Of Casing…
  • 26. So What? If You Are A .NET Developer…  You may ask yourself why you need something new Why didn't the other guys simply join your .NET platform?  You will continue to use the CLR. It is your bridge to seamless integration with WinRT.  Access OS services directly using WinRT No wrappers around Windows API any more. The parts of the .NET class library you will use will shrink.
  • 27. So What? If You Are A C++ Developer…  Welcome to the world of XAML! You do not need to be jealous any more because the .NET guys have WPF ;-) Freely combine e.g. Direct3D with XAML-based UI parts.  You can easily program WinRT with C++/CX If you want/need to you can stick to ISO C++ by using WRL.  Language interop with .NET and JavaScript Share components with .NET and JavaScript developers.
  • 28. So What? If You Are A JavaScript Developer…  Use your existing skillset to write apps for Windows You can enter the upcoming Windows Store.  Visit my next session about WinRT and JavaScript
  • 29. Programming Windows 8 With WinRT Rainer Stropek software architects gmbh Mail rainer@timecockpit.com Q&A Web Twitter http://www.timecockpit.com @rstropek Thank You For Coming. Saves the day.

Editor's Notes

  • #5: This slide contains animations and cannot be printed appropriately. The next (hidden) slide contains the status of the slide after all animation. It is fine for printing.
  • #6: This slide is for printing only (same content as animated slide before).