SlideShare a Scribd company logo
1 of 26
Agenda
Metro SDK API
WinRT API
•    New APIs
•    Operation that can block implemented as asynchronous operation


Win32 API
•    Subset of Win32 API available in Metro
•    Similar Win32 API may be part of Metro SDK
    • InitializeCriticalSectionAndSpinCount -> InitializeCriticalSectionEx


COM Components
•    Some OS components available under Metro
Identifying Non Metro SDK API usage
Documentation
•   http://msdn.microsoft.com/library/windows/apps/br211369

Preprocessor define
•   WINAPI_FAMILY=WINAPI_PARTITION_APP
•   Add the define to C++ preprocessor settings in Projects settings
•   Compiler stops after 100 errors so may not get full list API not available in Metro SDK

Windows App Certification Kit tool
•   Create an Appx package with app binaries
•   Run resulting package through tool
•   <Program Files>Windows Kits8.0App Certification Kitappcert.exe
Get the desktop app ready for Porting
Build with VS 11
•   Compile, test on Windows 8 desktop

Desktop API usage
•   Use alternate Win32 APIs available in Metro SDK
•   Wrap API usage in abstractions
Asynchronous operations
WinRT APIs are asynchronous
•   Refactor existing code to consume asynchronous operations
•   DO refactor code to deal with partial data
•   DO keep UI responsive while asynchronous operations are in progress

Convert long running operations to asynchronous
•    Schedule long running work on thread pool
•    DO return partial results as and when available
•    Options
    • Rewrite existing code
    • Write a wrapper that invokes existing code on a thread pool thread
Isolate core logic
Separate platform specific code into abstractions
•   Refactor direct call to APIs to call an abstraction over the API
•   Use existing abstraction in libraries if available

Use Standard C++ libraries for core logic
•   Refactor core logic to operate on buffers, containers, etc
UI
User and GDI based UI
•   Rewrite


DirectX UI
•   Available in Metro
•   Use DirectX template as starting point
•   Template sets up the start up code required for Metro


Options for UI in Metro
•   XAML
•   DirectX
MFC
MFC not available under Metro
•   Rewrite


Options in Metro
•  UI
  • XAML
  • DirectX
• Form based App
  • Consider XAML databinding
• Utility classes
  • Consider STL, CRT
CRT
Subset available in Metro
•   APIs for concepts not available in Metro not available in CRT




APIs available in Metro but not recommended
•   File api
•   ANSI char functions
CRT
APIs not in Metro
•   Multi-byte functions: mb* and _ismb*
•   Process control: exec* and spawn functions
•   Threading: beginthread* and endthread*
•   Heap and stack functions: heapwalk, heapmin, resetstkoflw(), …
•   Environment variable functions and globals putenv, getenv, _enviorn, …
•   Console function, cprintf, cscanf, …
•   Port functions, outp, inp, …
•   Pipe functions: pipe, popen, pclose, …
ATL
Subset available in Metro
APIs available in metro
•   DLL server
•   COM objects (without IDispatch)
•   CStringW
•   ATL container classes
•   CCriticalSection, CEvent, CMutex, CSemaphore, CMutexLock
•   CComVariant
•   CComSafeArray
•   CComBSTR
Static Libs
Consumption of WinRT in static libs
•   C++/CX – supported
•   WRL – supported

Authoring WinRT component in static libs
•    C++/CX – not supported
•    WRL – partially supported
    • Have to take explicit steps to make sure that component is part of the final binary
    • WrlCreatorMapIncludePragma used to make sure that specific class is pulled in from static lib
Using existing code in Metro
(or do I need to convert all my code to WinRT components)

C++ Metro Apps can use existing static libs, DLLs
and COM components
•   DO make sure that the existing code is ported to use Metro SDK APIs
•   Link to static libs or import library as usual
•   Include binary components in APPX package, DLLs are app local

Using COM components
•   Use Reg-Free COM for activation
•   Activation through new API - CoCreateInstanceFromAppx
Convert types to WinRT types
DO change variable to WinRT type if
•    It frequently crosses boundary AND
•    Costly to convert between the two types
•    String and Array as input parameters to WinRT API can be efficiently converted without copying
    • StringRef, ArrayRef add a WinRT veneer using “borrow” semantics

Container and Collections
•   Requires copy to go from std::* to Platform::*
•   std::* efficient compared to Platform::*
•   Use std::* or Platform::* based on how often collection contents change vs how often they cross
    WinRT boundary
Strategies to create WinRT
component
Choose technology
•   C++/CX, WRL, Your own implementation

Wrapper
•   Define interface and in the implementation delegate to existing C++ code after any type
    conversions
•   Creates a WINRT veneer over your existing code

Covert existing code
•   Rewrite code to use WinRT types and concepts
•   Have good reasons to go this route
Converting COM components to
WinRT technology
Choose the
•   C++/CX, WRL, Your own implementation
•   Component already written using ATL, may be easier to move to WRL

Steps
•   Create WinRT interfaces corresponding to the previous interfaces
•   Port to one of the above technologies
•   Generate WinMD (if using IDL, modify MDIL flags)
•   Ship DLL and WinMD for others to consume the component
Technologies to use during porting
Language and Libraries
•   CRT and STL for utility functions and classes
•   C++/CX and/or WRL to interact with WinRT
•   See other talks for details about C++/CX and WRL

UI
•   XAML
•   DirectX
Conclusion
Metro SDK
•   Work involved to move but not all throw away
•   Lot of the business logic, core application logic is portable

UI
•   DirectX – easy
•   Win32 – rewrite in C++ using Modern UI framework

C++
•   Two way to interact with WinRT C++/CX, WRL
•   Use familiar C++ concepts and types for parts that don’t directly interact with platfrom

Build, test, validate often
•   Use Release configuration
Porting tometro

More Related Content

What's hot

.net CLR
.net CLR.net CLR
.net CLRDevTalk
 
Kotlin Multiplatfom In Action
Kotlin Multiplatfom In ActionKotlin Multiplatfom In Action
Kotlin Multiplatfom In ActionMarko Mitic
 
Swift should I switch?
Swift should I switch?Swift should I switch?
Swift should I switch?wulfgeng
 
Непрерывное тестирование для улучшения качества кода
Непрерывное тестирование для улучшения качества кодаНепрерывное тестирование для улучшения качества кода
Непрерывное тестирование для улучшения качества кодаSQALab
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compilerMohit kumar
 
C++ in windows phone apps
C++ in windows phone appsC++ in windows phone apps
C++ in windows phone appsMirco Vanini
 
Codasip application class RISC-V processor solutions
Codasip application class RISC-V processor solutionsCodasip application class RISC-V processor solutions
Codasip application class RISC-V processor solutionsRISC-V International
 
Type Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersMarcus Denker
 

What's hot (13)

.net CLR
.net CLR.net CLR
.net CLR
 
Session 1
Session 1Session 1
Session 1
 
C# Application lifecycle
C# Application lifecycleC# Application lifecycle
C# Application lifecycle
 
intoduction to java
intoduction to javaintoduction to java
intoduction to java
 
LLDB + Python for iOS developers
LLDB + Python for iOS developersLLDB + Python for iOS developers
LLDB + Python for iOS developers
 
Kotlin Multiplatfom In Action
Kotlin Multiplatfom In ActionKotlin Multiplatfom In Action
Kotlin Multiplatfom In Action
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Swift should I switch?
Swift should I switch?Swift should I switch?
Swift should I switch?
 
Непрерывное тестирование для улучшения качества кода
Непрерывное тестирование для улучшения качества кодаНепрерывное тестирование для улучшения качества кода
Непрерывное тестирование для улучшения качества кода
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compiler
 
C++ in windows phone apps
C++ in windows phone appsC++ in windows phone apps
C++ in windows phone apps
 
Codasip application class RISC-V processor solutions
Codasip application class RISC-V processor solutionsCodasip application class RISC-V processor solutions
Codasip application class RISC-V processor solutions
 
Type Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode Interpreters
 

Similar to Porting tometro

Radu vunvulea building and testing windows 8 metro style applications using ...
Radu vunvulea  building and testing windows 8 metro style applications using ...Radu vunvulea  building and testing windows 8 metro style applications using ...
Radu vunvulea building and testing windows 8 metro style applications using ...Radu Vunvulea
 
Building apps with common code for windows 8 and windows phone 8 (WP8)
Building apps with common code for windows 8 and windows phone 8 (WP8)Building apps with common code for windows 8 and windows phone 8 (WP8)
Building apps with common code for windows 8 and windows phone 8 (WP8)Tamir Dresher
 
A Developer's View of Windows 8
A Developer's View of Windows 8A Developer's View of Windows 8
A Developer's View of Windows 8Andrei Marukovich
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineGaruda Trainings
 
Windows 8 Hot or Not
Windows 8 Hot or NotWindows 8 Hot or Not
Windows 8 Hot or Notpwlodek
 
Windows 8 Development Stack
Windows 8 Development StackWindows 8 Development Stack
Windows 8 Development StackDev2
 
Introduction to dot net framework by vaishali sahare [katkar]
Introduction to dot net framework by vaishali sahare [katkar]Introduction to dot net framework by vaishali sahare [katkar]
Introduction to dot net framework by vaishali sahare [katkar]vaishalisahare123
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1Sisir Ghosh
 
Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsQuontra Solutions
 
.Net overviewrajnish
.Net overviewrajnish.Net overviewrajnish
.Net overviewrajnishRajnish Kalla
 
Visual programming lab
Visual programming labVisual programming lab
Visual programming labSoumya Behera
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
Forge - DevCon 2016: Drawings! Drawings! Everywhere!
Forge - DevCon 2016: Drawings! Drawings! Everywhere!Forge - DevCon 2016: Drawings! Drawings! Everywhere!
Forge - DevCon 2016: Drawings! Drawings! Everywhere!Autodesk
 
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep diveITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep diveITCamp
 
Continuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with KubernetesContinuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with KubernetesLuke Marsden
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDocker, Inc.
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overviewscdhruv5
 
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...Amir Zmora
 

Similar to Porting tometro (20)

Radu vunvulea building and testing windows 8 metro style applications using ...
Radu vunvulea  building and testing windows 8 metro style applications using ...Radu vunvulea  building and testing windows 8 metro style applications using ...
Radu vunvulea building and testing windows 8 metro style applications using ...
 
Building apps with common code for windows 8 and windows phone 8 (WP8)
Building apps with common code for windows 8 and windows phone 8 (WP8)Building apps with common code for windows 8 and windows phone 8 (WP8)
Building apps with common code for windows 8 and windows phone 8 (WP8)
 
A Developer's View of Windows 8
A Developer's View of Windows 8A Developer's View of Windows 8
A Developer's View of Windows 8
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement online
 
Windows 8 Hot or Not
Windows 8 Hot or NotWindows 8 Hot or Not
Windows 8 Hot or Not
 
Windows 8 Development Stack
Windows 8 Development StackWindows 8 Development Stack
Windows 8 Development Stack
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Introduction to dot net framework by vaishali sahare [katkar]
Introduction to dot net framework by vaishali sahare [katkar]Introduction to dot net framework by vaishali sahare [katkar]
Introduction to dot net framework by vaishali sahare [katkar]
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutions
 
.Net overviewrajnish
.Net overviewrajnish.Net overviewrajnish
.Net overviewrajnish
 
Visual programming lab
Visual programming labVisual programming lab
Visual programming lab
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Forge - DevCon 2016: Drawings! Drawings! Everywhere!
Forge - DevCon 2016: Drawings! Drawings! Everywhere!Forge - DevCon 2016: Drawings! Drawings! Everywhere!
Forge - DevCon 2016: Drawings! Drawings! Everywhere!
 
Eco system apps
Eco system appsEco system apps
Eco system apps
 
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep diveITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
 
Continuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with KubernetesContinuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with Kubernetes
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm Architecture
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
WebRTC Standards & Implementation Q&A - The Internals of WebRTC Browsers Impl...
 

Porting tometro

  • 1.
  • 3.
  • 4. Metro SDK API WinRT API • New APIs • Operation that can block implemented as asynchronous operation Win32 API • Subset of Win32 API available in Metro • Similar Win32 API may be part of Metro SDK • InitializeCriticalSectionAndSpinCount -> InitializeCriticalSectionEx COM Components • Some OS components available under Metro
  • 5. Identifying Non Metro SDK API usage Documentation • http://msdn.microsoft.com/library/windows/apps/br211369 Preprocessor define • WINAPI_FAMILY=WINAPI_PARTITION_APP • Add the define to C++ preprocessor settings in Projects settings • Compiler stops after 100 errors so may not get full list API not available in Metro SDK Windows App Certification Kit tool • Create an Appx package with app binaries • Run resulting package through tool • <Program Files>Windows Kits8.0App Certification Kitappcert.exe
  • 6.
  • 7. Get the desktop app ready for Porting Build with VS 11 • Compile, test on Windows 8 desktop Desktop API usage • Use alternate Win32 APIs available in Metro SDK • Wrap API usage in abstractions
  • 8. Asynchronous operations WinRT APIs are asynchronous • Refactor existing code to consume asynchronous operations • DO refactor code to deal with partial data • DO keep UI responsive while asynchronous operations are in progress Convert long running operations to asynchronous • Schedule long running work on thread pool • DO return partial results as and when available • Options • Rewrite existing code • Write a wrapper that invokes existing code on a thread pool thread
  • 9. Isolate core logic Separate platform specific code into abstractions • Refactor direct call to APIs to call an abstraction over the API • Use existing abstraction in libraries if available Use Standard C++ libraries for core logic • Refactor core logic to operate on buffers, containers, etc
  • 10.
  • 11. UI User and GDI based UI • Rewrite DirectX UI • Available in Metro • Use DirectX template as starting point • Template sets up the start up code required for Metro Options for UI in Metro • XAML • DirectX
  • 12. MFC MFC not available under Metro • Rewrite Options in Metro • UI • XAML • DirectX • Form based App • Consider XAML databinding • Utility classes • Consider STL, CRT
  • 13.
  • 14. CRT Subset available in Metro • APIs for concepts not available in Metro not available in CRT APIs available in Metro but not recommended • File api • ANSI char functions
  • 15. CRT APIs not in Metro • Multi-byte functions: mb* and _ismb* • Process control: exec* and spawn functions • Threading: beginthread* and endthread* • Heap and stack functions: heapwalk, heapmin, resetstkoflw(), … • Environment variable functions and globals putenv, getenv, _enviorn, … • Console function, cprintf, cscanf, … • Port functions, outp, inp, … • Pipe functions: pipe, popen, pclose, …
  • 16. ATL Subset available in Metro APIs available in metro • DLL server • COM objects (without IDispatch) • CStringW • ATL container classes • CCriticalSection, CEvent, CMutex, CSemaphore, CMutexLock • CComVariant • CComSafeArray • CComBSTR
  • 17.
  • 18. Static Libs Consumption of WinRT in static libs • C++/CX – supported • WRL – supported Authoring WinRT component in static libs • C++/CX – not supported • WRL – partially supported • Have to take explicit steps to make sure that component is part of the final binary • WrlCreatorMapIncludePragma used to make sure that specific class is pulled in from static lib
  • 19. Using existing code in Metro (or do I need to convert all my code to WinRT components) C++ Metro Apps can use existing static libs, DLLs and COM components • DO make sure that the existing code is ported to use Metro SDK APIs • Link to static libs or import library as usual • Include binary components in APPX package, DLLs are app local Using COM components • Use Reg-Free COM for activation • Activation through new API - CoCreateInstanceFromAppx
  • 20. Convert types to WinRT types DO change variable to WinRT type if • It frequently crosses boundary AND • Costly to convert between the two types • String and Array as input parameters to WinRT API can be efficiently converted without copying • StringRef, ArrayRef add a WinRT veneer using “borrow” semantics Container and Collections • Requires copy to go from std::* to Platform::* • std::* efficient compared to Platform::* • Use std::* or Platform::* based on how often collection contents change vs how often they cross WinRT boundary
  • 21. Strategies to create WinRT component Choose technology • C++/CX, WRL, Your own implementation Wrapper • Define interface and in the implementation delegate to existing C++ code after any type conversions • Creates a WINRT veneer over your existing code Covert existing code • Rewrite code to use WinRT types and concepts • Have good reasons to go this route
  • 22. Converting COM components to WinRT technology Choose the • C++/CX, WRL, Your own implementation • Component already written using ATL, may be easier to move to WRL Steps • Create WinRT interfaces corresponding to the previous interfaces • Port to one of the above technologies • Generate WinMD (if using IDL, modify MDIL flags) • Ship DLL and WinMD for others to consume the component
  • 23. Technologies to use during porting Language and Libraries • CRT and STL for utility functions and classes • C++/CX and/or WRL to interact with WinRT • See other talks for details about C++/CX and WRL UI • XAML • DirectX
  • 24.
  • 25. Conclusion Metro SDK • Work involved to move but not all throw away • Lot of the business logic, core application logic is portable UI • DirectX – easy • Win32 – rewrite in C++ using Modern UI framework C++ • Two way to interact with WinRT C++/CX, WRL • Use familiar C++ concepts and types for parts that don’t directly interact with platfrom Build, test, validate often • Use Release configuration

Editor's Notes

  1. Mentions these are not in order of importance. Hint of Windows on ARM, but don’t add it as a bullet.