building mixed-language apps

31
Building mixed- language apps Alan Ludwig Senior Software Development Engineer 4-100

Upload: fedora

Post on 23-Mar-2016

60 views

Category:

Documents


0 download

DESCRIPTION

Building mixed-language apps. Alan Ludwig Senior Software Development Engineer 4-100. The Windows Runtime makes it possible for you to write great apps using more than one language. The Windows Runtime (WinRT). APIs. Cross-language i nfrastructure. A version of Windows. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Building mixed-language apps

Building mixed-language appsAlan LudwigSenior Software Development Engineer4-100

Page 2: Building mixed-language apps

The Windows Runtime makes it possible for you to write great apps using more than one language

Page 3: Building mixed-language apps

The Windows Runtime (WinRT)

APIs A versionof Windows

Cross-language

infrastructure

Page 4: Building mixed-language apps

What’s the best language foryour Windows 8 apps?The language you already knowThe language your component is already written inThe language that has access to the features you needThe language that provides the right performanceThe language of your choice

Page 5: Building mixed-language apps

How do I do that?

When you write a Windows Runtime component,you can consume it in JavaScript, C#/VB, or C++

Page 6: Building mixed-language apps

The same cross-language infrastructure that was used to create thousands of Windows Runtime APIs is available for you to write your own Windows Runtime APIs

Page 7: Building mixed-language apps

Demo

Hybrid JavaScript and C++ Sample

Page 8: Building mixed-language apps

Only where neededKeep it simpleAsync everywhere Mind your threads

How do I make it great?

Page 9: Building mixed-language apps

Only where needed

Indirect function callsType conversion

Page 10: Building mixed-language apps

Examples of type conversion

WinRT Type C++ JavaScript C# (.NET)

HSTRING Platform::String var (string) StringGUID GUID var (string) GUIDUInt32 uint32 var (double) uint32DateTime (FILETIME) var (date) DateTimeOffset

Page 11: Building mixed-language apps

Keep it simple

Designing good Windows Runtime interfaces is similarto good OO design

Page 12: Building mixed-language apps

Async everywhere

Use the async pattern for long running operationsThe language projections make this easy

Page 13: Building mixed-language apps

Windows::Foundation::IAsyncOperation<uint32>^ DemoLib::GetCountAsync(){

auto async = concurrency::create_async(// your lambda here[this](){ return _count;});return async;

}

Async operation in C++

Page 14: Building mixed-language apps

public Windows.Foundation.IAsyncOperation<UInt32> GetCountAsync(){return (Windows.Foundation.IAsyncOperation<UInt32>)Task<UInt32>.Run(

() => {return _count;} );

}

Async operation in C#

Page 15: Building mixed-language apps

Mind your threads

Writing great components requires some basic knowledge of threading issues

Page 16: Building mixed-language apps

UI is always thread affine

Page 17: Building mixed-language apps

ThreadingUI

Thr

ead

Wor

ker T

hrea

d

Callasync API

Create task

Other work Update UI Continue

Do workCall

completion

How do I get back to the main thread?

Page 18: Building mixed-language apps

Techniques to get back to the main threadDispatching via the UI elementDispatching via the core windowProxies and stubs

Page 19: Building mixed-language apps

if (output->Dispatcher->HasThreadAccess()){ output->Text += "Count Changed (thread access)! Count is " + newCount.ToString() + "\n";}

Dispatching via the UI element

Page 20: Building mixed-language apps

else{ output->Dispatcher->RunAsync( Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler( [this, newCount]() -> void { output->Text += "Count Changed (no thread access)! Count is " + newCount.ToString() + "\n";}));}

Dispatching via the UI element

Page 21: Building mixed-language apps

Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(

Windows::UI::Core::CoreDispatcherPriority::Normal,ref new Windows::UI::Core::DispatchedHandler(

[this,value](){CountChanged(this, value);}

));

Dispatching via the core window

Page 22: Building mixed-language apps

The Windows Runtime will automatically move your calls back to the right thread if proxies and stubs are available

Page 23: Building mixed-language apps

event Windows::Foundation::EventHandler<uint32>^ CountChanged;

event Windows::Foundation::TypedEventHandler<IDemoLib^, uint32>^ CountChanged;

EventHandler vs. TypedEventHandler

Page 24: Building mixed-language apps

Create proxies and stubs for yourWindows Runtime components

Page 25: Building mixed-language apps

Demo

Creating a Windows Runtime in-process component sample (C++/CX)

Page 26: Building mixed-language apps

The same cross-language infrastructure that was used to create thousands of Windows Runtime APIs is available for you to write your own Windows Runtime APIs

Page 27: Building mixed-language apps

Only where neededKeep it simpleAsync everywhere Mind your threads

How do I make it great?

Page 28: Building mixed-language apps

• 10/30/2012 11:45 – B33 Baker – Bringing existing C++ code to Windows Store apps

• 11/1/2012 12:00 – B33 Hood – Gaming reimagined: Gaming case studies

Related Sessions

A list of sessions will be sent one week prior to the event

Page 31: Building mixed-language apps

© 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.