introducing windows runtime in windows 8

36

Upload: microsoft-developer-network-msdn-belgium-and-luxembourg

Post on 14-Nov-2014

4.261 views

Category:

Technology


0 download

DESCRIPTION

More info on http://www.techdays.be

TRANSCRIPT

Introducing WinRT in Windows 8Built on //build/ content

Bart J.F. De SmetSoftware EngineerMicrosoft Corporation

Agenda• What is the Windows Runtime?• Goals & Architecture

• Inside a Windows Metro style app• JavaScript, C++, C#

• What are Windows Runtime Objects?• Classes, Interfaces and Patterns

What is the Windows Runtime?

DevicesSensor

sGeolocatio

nPortable NFC

Communications & DataContracts

XML

Web

SMSNetworking

Notifications

Local & Cloud Storage

Streams

Background Transfer

User InterfaceHTML5/CSS XAML DirectX Controls

Input Accessibility Printing

Data Binding

TilesSVG

Metro style application APIs

FundamentalsApplication

ServicesAuthenticati

onCryptograph

yGlobalizatio

nMemory

ManagementThreading/Timers

MediaVisual Effects

Playback

PlayToCaptur

e

Windows 8

Windows Kernel Services

JavaScript(Chakra)

C/C++ C#, VB

Metro style Apps

Communication

& Data

Application Model

Devices & Printing

Windows Runtime APIs

Graphics & Media

XAML HTML / CSS

HTMLJavaScri

pt

CC++

C#VB

Desktop Apps

Win32

.NET SL

Internet Explore

r

Syst

em

Serv

ices

Vie w

Model

Contr

oll

er

Kern el

The Windows Runtime is the solid, efficient foundation

for building great Metro style apps

Windows Runtime Architecture

Windows Metadata & Namespace

Language Projection

Windows Core

Windows Runtime Core

XAML Storage …Network

UI Pickers MediaControls

Metro style app

Runtime Broker

Language Support (CLR, WinJS, CRT)

Web Host (HTML, CSS, JavaScript))

The Windows 8 Developer Experience• Easy to build a Metro style app

• Dramatic improvements in developer experience

• Freedom of choice – language, library, markup

Design Principles• Major improvement to developer experience• Great IntelliSense & tooling

• Responsive and Fluid• Async APIs where they are needed

• App-Centric Platform• Well managed app-to-app contracts

• Platform based Versioning• Apps keep running on future Windows versions

DemoCreating a basic Metro style app in HTML/JavaScript

Inside a Windows Metro Style app

Windows Metadata & Namespace

Windows Runtime Architecture

Windows Metadata & Namespace

Language Projection

Windows Core

Windows Runtime Core

XAML Storage …Network

UI Pickers MediaControls

Metro style app

Runtime Broker

Language Support (CLR, WinJS, CRT)

Web Host (HTML, CSS, JavaScript))

Windows Metadata• Concise, complete description of the Windows Runtime

• Generated natively from C++ or C#/VB Compiler

• Efficient binary format derived CLI Metadata• Same structures, different meanings

• Rich enough to allow multi-language projection generation

• Full IntelliSense on statically known information

The Windows Namespace• Windows.* Runtime objects are in a simple, unified,

hierarchical namespace

• Great IntelliSense and browsing in Visual Studio

• One clear type for each function

• Catalog is extensible but private• Your apps can add objects (in C++/C#)• Objects can be seen from JavaScript

Windows Runtime Basic TypesStrings HSTRING Avoids copying in multiple

languages

Basic Types INT32, UINT64 * Pointers allowed in limited cases

Enumerations enum AsyncStatus Flag or non-flag styles

Structures struct Rect; Can contain strings, but not interfaces

Simple Arrays INT32 [] For very basic collections

Interfaces IInspectable Methods are defined in interfaces

Generic Interfaces IVector<T> Type-generic interface

Runtime Class Windows.Storage.StorageFile Binds interfaces to make a class

DemoInspecting Windows Metadata files using ILDASM

What are Windows Runtime objects?

Windows Metadata & Namespace

Windows Runtime Architecture

Language Projection

Windows Core

Windows Runtime Core

XAML Storage …Network

UI Pickers MediaControls

Metro style app

Runtime Broker

Language Support (CLR, WinJS, CRT)

Web Host (HTML, CSS, JavaScript))

Language Projection

Windows Runtime Core

Shell32.dll

What is a Windows Runtime Object?

Object

IInspectableIUnknown

IStorageItemInformationIStorageItemIStorageFile

Interfaces

FileInformation

Runtime Class

Activation Store (Registry)

Windows Metadata (Disk)

Projections

Object

IInspectableIUnknown

Windows Metadata

C++ App

Pro

jecti

on

CLR

C#/VB App

Pro

jecti

on

HTML AppCh

akra

Pro

jecti

on

Object Creation

Start

App asks to create object

Pass Name to RoActivateInsta

nce

Find DLL using Catalog Load DLL

Call DllGet-ActivationFactor

y

Object created by

implementation code

IInspectable returned

Projection creates wrapper

(using metadata)

Object bound to wrapper

Wrapper returned to App

End

App

Projection

WinRT Object

Manager

WinRT Object

Versioning

Object

IInspectableIUnknown

Windows Metadata

v8

App

Pro

jecti

on

Futu

re W

ind

ow

sW

indow

s 8

Object

IInspectableIUnknown

Windows Metadata

v9

App

Pro

jecti

on

DemoWriting hybrid C#/JavaScript apps

Windows Runtime PatternsCollections IVector<T>, IVectorView<T>,

IMap<T>Iterators, Collections and events cross-language

Delegates delegate AsyncActionCompletedHandler

Encapsulate the context to call back to an object

Events IApplicationLayout::LayoutChanged Lists of callback recipients

PropertySet interface IPropertySet Collection of items with varying types

Async Interface ReceivePropertiesOperation A way to get a delayed result without blocking

Contracts Windows.ApplicationModel.DataTransferManager

Connect Apps to Windows Extension Points

Collections

Array

IInspectableIUnknown

IVector<T>

IVectorView<T>

IObservableVector<T>

Associative Collection

IInspectableIUnknown

IMap<T>

IMapView<T>

IObservableMap<T>

C++ AppSTL-style Projectio

n

CLR

C#/VB AppIEnumerable

(T) style Projectio

n

HTML AppCh

akra

JavaScript

Projection

Asynchronous Objects• Basic requirement for Metro style apps• Always responsive, ready• “Long running” APIs must be delivered as async

• Simpler to allow apps to make synchronous calls• But then bad apps can overwhelm quality of system

• Instead, build async into API shape• And have language projections integrate it deeply

Asynchronous Objects in C#

var ui = new CameraCaptureUI();ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3);

var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);

if (file != null) { var bitmap = new BitmapImage(); bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read)); Photo.Source = bitmap;}

[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindow")]static extern int capCreateCaptureWindow( string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);

[DllImport("avicap32.dll")] static extern bool capGetDriverDescription( int wDriverIndex, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszVer, int cbVer);

// more and more of the same

The C# code you have to write today…

DemoHow Patterns Work – Collections & Async

App

Threading

Windows UI

Object

Main UI Thread

Windows

Object

Threadpool

App Code App Code App Code

Windows

Object

Windows Runtime Threading• Three main types of object• Thread bound – works only on the thread where it was created –

most UI• Thread flexible – works on any thread, uses locking if needed to

control simultaneous access• Brokered – out of process

• UI runs in single threaded environment that is not reentrant (“Application STA”) • Callbacks can only enter if they are related to an outgoing call

• Most non-UI runs in any thread

RuntimeBroker.exe

Brokered Objects

Windows Runtime Object

IInspectable

IUnknown

App

Pro

jecti

on

Pro

xy

Summary• The Windows Runtime is the solid, efficient

foundation for the new Windows 8 developer platform

• Build Metro style apps easily with the Windows Runtime

• Windows available in your choice of language and environment

• One Windows API, Natural and Familiar everywhere

Q&A

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.