SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Creating Windows Runtime Components
Mirco Vanini
WinRT Components
Microsoft® MVP Windows Embedded
Agenda
 Libraries for Windows Store Apps
 Recap - WinRT Internal
 Projection
 Windows Runtime Components via C#
 Understand the Cost
 When to Create Managed Windows
Runtime Components
 Q&A
 Links
 Contatti
Libraries for Windows Store Apps
 Class Library (Windows Store Apps)
.NET library with classes and methods that are
available for Windows Store apps.
 Portable Class Library
Only a subset of .NET library is available
(depends on target platform).
 Windows Runtime Component
Consumed in any language that supports
WinRT
WinRT – 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))
WinRT - object
 COM Based !
o IUnknown
• AddRef
• Release
• QueryInterface
o IDispatch
o IInspectable
• GetIids
• GetRuntimeClassName
• GetTrustLevel
o Windows Metadata (WinMD) - ECMA-335
Object
Windows Runtime APIs
 Available to all programming languages
 Requires a language neutral type
system
Windows
Runtime
JavaScript
C#/VBC++
APIs in multiple languages
 Many languages use PascalCasing for names
of types, methods, properties, and events
 JavaScript has well established naming
conventions
o “Types” are PascalCased
o Methods and Properties are camelCased
o Events are all lowercase
 Windows Runtime uses PascalCasing for types
and members
 Windows Runtime maps JavaScript
methods, properties and event names to its
conventions
Windows Runtime types
Windows Runtime types - Strings
 Immutable or mutable?
o Immutable – JavaScript, .NET; Mutable – C++
 Null
o JavaScript: null is an object, string is a type
o C++: std::string has no 'null' semantics
o .NET System.String: reference type has a 'null'
distinguished value
 As a result…
o Windows Runtime: string's immutable, no null
representation
Windows Runtime types - References
 Target languages handle pointers and
references differently
o C++: All types can be passed by value or by
reference
o .NET: Objects are passed by reference, value types
by value
o JavaScript: Objects passed by reference, numbers
passed by value
o Windows Runtime: Objects (Interfaces) passed by
reference, all other types passed by value
 As a result…
o Windows Runtime: method parameters are [in] or
[out], never [in, out]
Projections
Object Creation
Runtime Callable Wrapper
 The common language runtime exposes COM
objects through a proxy called the runtime
callable wrapper (RCW).
 The runtime creates exactly one RCW for each
COM object, regardless of the number of
references that exist on that object.
 The runtime maintains a single RCW per
process for each object
The standard wrapper enforces
built-in marshaling rules. For
example, when a .NET client passes
a String type as part of an argument
to an unmanaged object, the
wrapper converts the string to a
BSTR type. Should the COM object
return a BSTR to its managed
caller, the caller receives a String
Windows Runtime Components via C#/VB
 With the .NET Framework 4.5, you can use
managed code to create your own Windows
Runtime types, packaged in a Windows
Runtime component.
 You can use your component in Windows Store
apps with C++, JavaScript, Visual Basic, or C#
Traditional COM in Managed Code
ComVisible(true), Guid("06D7901C-9045-4241-B8A0-39A1AC0F8618")]
public interface IWindowsApiSample
{
string HelloWorld();
}
[ComVisible(true), [ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IWindowsApiSample))]
public class WindowsApiSample : IWindowsApiSample
{
public string HelloWorld() {
return "Hello, World!";
}
}
Windows Runtime in managed code
Sample
public sealed class MyClassLibrary
{
public string HelloWorld()
{
return "Hello, World!";
}
}
Windows Runtime Components Rules
 Public classes must be sealed.
 All public types must have a root namespace
that matches the assembly name.
 The fields, parameters, and return values of all
the public types and members in your
component must be Windows Runtime types.
 A public class or interface cannot:
o Be generic.
o Implement an interface that is not a Windows
Runtime interface.
o Derive from types that are not in the Windows
Runtime.
.NET Framework mappings of Windows Runtime types
demo
Windows Runtime Components Rules
 Using the Windows Runtime from JavaScript
and managed code:
o The Windows Runtime can be called from either
JavaScript or managed code.
o Windows Runtime objects can be passed back and
forth between the two.
o Events can be handled from either side.
o The ways you use Windows Runtime types in the two
environments differ in some details, because
JavaScript and the .NET Framework support the
Windows Runtime differently.
Windows Runtime Components Rules
 You can throw any exception type that is
included in the .NET for Windows Store apps -
supported APIs.
 You can't declare your own public exception
types in a Windows Runtime component.
 The way the exception appears to the caller
depends on the way the calling language
supports the Windows Runtime.
o In JavaScript, the exception appears as an object in
which the exception message is replaced by a stack
trace.
o In C++, the exception appears as a platform
exception.
demo
Windows Runtime Components Rules
 You can return a managed type, created in
managed code, to JavaScript as if it were the
corresponding Windows Runtime type.
o When a managed type implements multiple
interfaces, JavaScript uses the interface that appears
first in the list.
o If you pass an unassigned JavaScript variable as a
string argument, what you get is the string
"undefined".
demo
Windows Runtime Components Rules
 You can declare events by using the standard
.NET Framework event pattern or other
patterns used by the Windows Runtime.
o When you expose an event in the Windows
Runtime, the event argument class inherits from
System.Object. It doesn't inherit from
System.EventArgs, as it would in the .NET
Framework, because EventArgs is not a Windows
Runtime type.
o If you declare custom event accessors for your
event, you must use the Windows Runtime event
pattern. Custom events and event accessors in
Windows Runtime Components
demo
Windows Runtime Components Rules
 To implement an asynchronous method in your
component, add "Async" to the end of the
method name and return one of the Windows
Runtime interfaces that represent
asynchronous actions or operations:
o IAsyncAction
o IAsyncActionWithProgress<TProgress>
o IAsyncOperation<TResult>
o IAsyncOperationWithProgress<TResult, TProgress>
Windows Runtime Components Rules
 For asynchronous actions and operations that
do not support cancellation or progress
reporting, you can use the AsAsyncAction or
AsAsyncOperation<TResult> extension method
to wrap the task in the appropriate interface.
demo
Understand the Cost
 Creating Windows Runtime Components using
managed languages is a powerful feature.
 It’s important to understand the cost when
you’re using it in projects:
o Windows Store apps built using native code don’t
require the CLR to run.
o The code written for the managed Windows Runtime
Component will be compiled just-in-time (JIT).
o The GC might pause your app while it’s performing
work.
When to Create Managed Windows Runtime
Components
 When to Create Managed Windows Runtime
Components:
o Consumable from all of the Windows Store
languages.
o Your team is more experienced in C# or Visual Basic
than in C++
o You have existing algorithms written in a managed
language
o …
When to Create Managed Windows Runtime
Components
 If you are creating a component for use only in
Windows Store apps with Visual Basic or
C#, and the component does not contain
Windows Store controls, consider using the
Class Library (Windows Store apps) template
instead of the Windows Runtime Component
template !!!
 Alternatives for Managed Projects:
o Class library for Windows Store
o Portable Class Library
o Extension SDK
Q&A
Links
Creating Windows Runtime Components in C#
and Visual Basic
Walkthrough: Creating a simple component in C#
or Visual Basic and calling it from JavaScript.
Windows Runtime Components in a .NET World
NetMF@Work
31 Maggio 2013 ore 09:00
Sede Microsoft
Via Avignone 10, Roma
Un’intera giornata per parlare di
.NET Micro Framework e .NET
Gadgeteer, dall’introduzione alla
realizzazione di soluzioni IoT reali
per un mondo di device
interconessi
feedback
10
Blog http://mircovanini.blogspot.com
Email info@proxsoft.it
Web www.proxsoft.it
Twitter @MircoVanini
Contatti
o feedback su:
• http://xedotnet.org/feedback
o codice feedback:
• ????

Weitere ähnliche Inhalte

Was ist angesagt?

Introducing type script
Introducing type scriptIntroducing type script
Introducing type scriptRemo Jansen
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)Moaid Hathot
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascriptAndrei Sebastian Cîmpean
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial Jm Ramos
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 
Nakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishNakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishsrivathsan.10
 

Was ist angesagt? (20)

Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 
Nakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishNakov dot net-framework-overview-english
Nakov dot net-framework-overview-english
 

Andere mochten auch

Windows 10 on Raspberry PI 2
Windows 10 on Raspberry PI 2Windows 10 on Raspberry PI 2
Windows 10 on Raspberry PI 2Mirco Vanini
 
IoT - What is it ?
IoT -  What is it ?IoT -  What is it ?
IoT - What is it ?Mirco Vanini
 
Different types of profiles in Slideshare
Different types of profiles in SlideshareDifferent types of profiles in Slideshare
Different types of profiles in SlideshareGP SRIRAM
 
Item pmb m4 t1 peratusan
Item pmb m4 t1 peratusanItem pmb m4 t1 peratusan
Item pmb m4 t1 peratusanUmmi Aqiraa
 
Universal Windows Platform Overview
Universal Windows Platform OverviewUniversal Windows Platform Overview
Universal Windows Platform OverviewJoshua Copeland
 
Getting Started Developing Universal Windows Platform (UWP) Apps
Getting Started Developing Universal Windows Platform (UWP) AppsGetting Started Developing Universal Windows Platform (UWP) Apps
Getting Started Developing Universal Windows Platform (UWP) AppsJaliya Udagedara
 
Introduction to universal windows platform(uwp) app development
Introduction to universal windows platform(uwp) app developmentIntroduction to universal windows platform(uwp) app development
Introduction to universal windows platform(uwp) app developmentThilina Wijerathne
 

Andere mochten auch (9)

Windows 10 on Raspberry PI 2
Windows 10 on Raspberry PI 2Windows 10 on Raspberry PI 2
Windows 10 on Raspberry PI 2
 
Complete unit ii notes
Complete unit ii notesComplete unit ii notes
Complete unit ii notes
 
IoT - What is it ?
IoT -  What is it ?IoT -  What is it ?
IoT - What is it ?
 
Different types of profiles in Slideshare
Different types of profiles in SlideshareDifferent types of profiles in Slideshare
Different types of profiles in Slideshare
 
Item pmb m4 t1 peratusan
Item pmb m4 t1 peratusanItem pmb m4 t1 peratusan
Item pmb m4 t1 peratusan
 
Universal Windows Platform Overview
Universal Windows Platform OverviewUniversal Windows Platform Overview
Universal Windows Platform Overview
 
Uwpに至る道
Uwpに至る道Uwpに至る道
Uwpに至る道
 
Getting Started Developing Universal Windows Platform (UWP) Apps
Getting Started Developing Universal Windows Platform (UWP) AppsGetting Started Developing Universal Windows Platform (UWP) Apps
Getting Started Developing Universal Windows Platform (UWP) Apps
 
Introduction to universal windows platform(uwp) app development
Introduction to universal windows platform(uwp) app developmentIntroduction to universal windows platform(uwp) app development
Introduction to universal windows platform(uwp) app development
 

Ähnlich wie Creating and Consuming Windows Runtime Components

Ähnlich wie Creating and Consuming Windows Runtime Components (20)

.Net Framework Introduction
.Net Framework Introduction.Net Framework Introduction
.Net Framework Introduction
 
Revealing C# 5
Revealing C# 5Revealing C# 5
Revealing C# 5
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
OpenDaylight and YANG
OpenDaylight and YANGOpenDaylight and YANG
OpenDaylight and YANG
 
Introdot Netc Sharp En
Introdot Netc Sharp EnIntrodot Netc Sharp En
Introdot Netc Sharp En
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
 
Intro.net
Intro.netIntro.net
Intro.net
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
2310 b 03
2310 b 032310 b 03
2310 b 03
 
Dot Net Framework
Dot Net FrameworkDot Net Framework
Dot Net Framework
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applications
 
.Net overview
.Net overview.Net overview
.Net overview
 
.Net Overview
.Net Overview.Net Overview
.Net Overview
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
CFInterop
CFInteropCFInterop
CFInterop
 
Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
 
.Net framework
.Net framework.Net framework
.Net framework
 
Microsoft dot net framework
Microsoft dot net frameworkMicrosoft dot net framework
Microsoft dot net framework
 
VB.Net Mod1.pptx
VB.Net Mod1.pptxVB.Net Mod1.pptx
VB.Net Mod1.pptx
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 

Mehr von Mirco Vanini

.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdfMirco Vanini
 
Debugging a .NET program after crash (Post-mortem debugging)
Debugging a .NET program after crash (Post-mortem debugging)Debugging a .NET program after crash (Post-mortem debugging)
Debugging a .NET program after crash (Post-mortem debugging)Mirco Vanini
 
Connect a chips to Azure
Connect a chips to AzureConnect a chips to Azure
Connect a chips to AzureMirco Vanini
 
Connect a chips to Azure
Connect a chips to AzureConnect a chips to Azure
Connect a chips to AzureMirco Vanini
 
How to modernise WPF and Windows Forms applications with Windows Apps SDK
How to modernise WPF and Windows Forms applications with Windows Apps SDKHow to modernise WPF and Windows Forms applications with Windows Apps SDK
How to modernise WPF and Windows Forms applications with Windows Apps SDKMirco Vanini
 
.NET Conf 2021 - Hot Topics Desktop Development
.NET Conf 2021 - Hot Topics Desktop Development.NET Conf 2021 - Hot Topics Desktop Development
.NET Conf 2021 - Hot Topics Desktop DevelopmentMirco Vanini
 
Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !Mirco Vanini
 
IoT support for .NET (Core/5/6)
IoT support for .NET (Core/5/6)IoT support for .NET (Core/5/6)
IoT support for .NET (Core/5/6)Mirco Vanini
 
Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !Mirco Vanini
 
IoT support for .NET Core
IoT support for .NET CoreIoT support for .NET Core
IoT support for .NET CoreMirco Vanini
 
IoT support for .NET Core - IoT Saturday 2020
IoT support for .NET Core - IoT Saturday 2020IoT support for .NET Core - IoT Saturday 2020
IoT support for .NET Core - IoT Saturday 2020Mirco Vanini
 
.NET Conf 2020 - Hot Topics Desktop Development
.NET Conf 2020 - Hot Topics Desktop Development.NET Conf 2020 - Hot Topics Desktop Development
.NET Conf 2020 - Hot Topics Desktop DevelopmentMirco Vanini
 
Are you ready for Microsoft Azure Sphere?
Are you ready for Microsoft Azure Sphere?Are you ready for Microsoft Azure Sphere?
Are you ready for Microsoft Azure Sphere?Mirco Vanini
 
IoT Day 2019 Naples - Microsoft Azure Shpere
IoT Day 2019 Naples - Microsoft Azure ShpereIoT Day 2019 Naples - Microsoft Azure Shpere
IoT Day 2019 Naples - Microsoft Azure ShpereMirco Vanini
 
Debugging with VS2019
Debugging with VS2019Debugging with VS2019
Debugging with VS2019Mirco Vanini
 
Optimising code using Span<T>
Optimising code using Span<T>Optimising code using Span<T>
Optimising code using Span<T>Mirco Vanini
 
Xe OneDay - Modernizing Enterprise Apps
Xe OneDay - Modernizing Enterprise AppsXe OneDay - Modernizing Enterprise Apps
Xe OneDay - Modernizing Enterprise AppsMirco Vanini
 

Mehr von Mirco Vanini (20)

.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf
 
Debugging a .NET program after crash (Post-mortem debugging)
Debugging a .NET program after crash (Post-mortem debugging)Debugging a .NET program after crash (Post-mortem debugging)
Debugging a .NET program after crash (Post-mortem debugging)
 
Connect a chips to Azure
Connect a chips to AzureConnect a chips to Azure
Connect a chips to Azure
 
Connect a chips to Azure
Connect a chips to AzureConnect a chips to Azure
Connect a chips to Azure
 
How to modernise WPF and Windows Forms applications with Windows Apps SDK
How to modernise WPF and Windows Forms applications with Windows Apps SDKHow to modernise WPF and Windows Forms applications with Windows Apps SDK
How to modernise WPF and Windows Forms applications with Windows Apps SDK
 
C# on a CHIPs
C# on a CHIPsC# on a CHIPs
C# on a CHIPs
 
.NET Conf 2021 - Hot Topics Desktop Development
.NET Conf 2021 - Hot Topics Desktop Development.NET Conf 2021 - Hot Topics Desktop Development
.NET Conf 2021 - Hot Topics Desktop Development
 
Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !Async Debugging A Practical Guide to survive !
Async Debugging A Practical Guide to survive !
 
IoT support for .NET (Core/5/6)
IoT support for .NET (Core/5/6)IoT support for .NET (Core/5/6)
IoT support for .NET (Core/5/6)
 
Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !
 
IoT support for .NET Core
IoT support for .NET CoreIoT support for .NET Core
IoT support for .NET Core
 
IoT support for .NET Core - IoT Saturday 2020
IoT support for .NET Core - IoT Saturday 2020IoT support for .NET Core - IoT Saturday 2020
IoT support for .NET Core - IoT Saturday 2020
 
.NET Conf 2020 - Hot Topics Desktop Development
.NET Conf 2020 - Hot Topics Desktop Development.NET Conf 2020 - Hot Topics Desktop Development
.NET Conf 2020 - Hot Topics Desktop Development
 
Are you ready for Microsoft Azure Sphere?
Are you ready for Microsoft Azure Sphere?Are you ready for Microsoft Azure Sphere?
Are you ready for Microsoft Azure Sphere?
 
IoT Day 2019 Naples - Microsoft Azure Shpere
IoT Day 2019 Naples - Microsoft Azure ShpereIoT Day 2019 Naples - Microsoft Azure Shpere
IoT Day 2019 Naples - Microsoft Azure Shpere
 
Debugging with VS2019
Debugging with VS2019Debugging with VS2019
Debugging with VS2019
 
Azure Sphere
Azure SphereAzure Sphere
Azure Sphere
 
Optimising code using Span<T>
Optimising code using Span<T>Optimising code using Span<T>
Optimising code using Span<T>
 
Azure Sphere
Azure SphereAzure Sphere
Azure Sphere
 
Xe OneDay - Modernizing Enterprise Apps
Xe OneDay - Modernizing Enterprise AppsXe OneDay - Modernizing Enterprise Apps
Xe OneDay - Modernizing Enterprise Apps
 

Kürzlich hochgeladen

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Kürzlich hochgeladen (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

Creating and Consuming Windows Runtime Components

  • 1. Creating Windows Runtime Components Mirco Vanini WinRT Components Microsoft® MVP Windows Embedded
  • 2. Agenda  Libraries for Windows Store Apps  Recap - WinRT Internal  Projection  Windows Runtime Components via C#  Understand the Cost  When to Create Managed Windows Runtime Components  Q&A  Links  Contatti
  • 3. Libraries for Windows Store Apps  Class Library (Windows Store Apps) .NET library with classes and methods that are available for Windows Store apps.  Portable Class Library Only a subset of .NET library is available (depends on target platform).  Windows Runtime Component Consumed in any language that supports WinRT
  • 4. WinRT – 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))
  • 5. WinRT - object  COM Based ! o IUnknown • AddRef • Release • QueryInterface o IDispatch o IInspectable • GetIids • GetRuntimeClassName • GetTrustLevel o Windows Metadata (WinMD) - ECMA-335 Object
  • 6. Windows Runtime APIs  Available to all programming languages  Requires a language neutral type system Windows Runtime JavaScript C#/VBC++
  • 7. APIs in multiple languages  Many languages use PascalCasing for names of types, methods, properties, and events  JavaScript has well established naming conventions o “Types” are PascalCased o Methods and Properties are camelCased o Events are all lowercase  Windows Runtime uses PascalCasing for types and members  Windows Runtime maps JavaScript methods, properties and event names to its conventions
  • 9. Windows Runtime types - Strings  Immutable or mutable? o Immutable – JavaScript, .NET; Mutable – C++  Null o JavaScript: null is an object, string is a type o C++: std::string has no 'null' semantics o .NET System.String: reference type has a 'null' distinguished value  As a result… o Windows Runtime: string's immutable, no null representation
  • 10. Windows Runtime types - References  Target languages handle pointers and references differently o C++: All types can be passed by value or by reference o .NET: Objects are passed by reference, value types by value o JavaScript: Objects passed by reference, numbers passed by value o Windows Runtime: Objects (Interfaces) passed by reference, all other types passed by value  As a result… o Windows Runtime: method parameters are [in] or [out], never [in, out]
  • 13. Runtime Callable Wrapper  The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW).  The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object.  The runtime maintains a single RCW per process for each object The standard wrapper enforces built-in marshaling rules. For example, when a .NET client passes a String type as part of an argument to an unmanaged object, the wrapper converts the string to a BSTR type. Should the COM object return a BSTR to its managed caller, the caller receives a String
  • 14. Windows Runtime Components via C#/VB  With the .NET Framework 4.5, you can use managed code to create your own Windows Runtime types, packaged in a Windows Runtime component.  You can use your component in Windows Store apps with C++, JavaScript, Visual Basic, or C#
  • 15. Traditional COM in Managed Code ComVisible(true), Guid("06D7901C-9045-4241-B8A0-39A1AC0F8618")] public interface IWindowsApiSample { string HelloWorld(); } [ComVisible(true), [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(IWindowsApiSample))] public class WindowsApiSample : IWindowsApiSample { public string HelloWorld() { return "Hello, World!"; } }
  • 16. Windows Runtime in managed code Sample public sealed class MyClassLibrary { public string HelloWorld() { return "Hello, World!"; } }
  • 17. Windows Runtime Components Rules  Public classes must be sealed.  All public types must have a root namespace that matches the assembly name.  The fields, parameters, and return values of all the public types and members in your component must be Windows Runtime types.  A public class or interface cannot: o Be generic. o Implement an interface that is not a Windows Runtime interface. o Derive from types that are not in the Windows Runtime. .NET Framework mappings of Windows Runtime types
  • 18. demo
  • 19. Windows Runtime Components Rules  Using the Windows Runtime from JavaScript and managed code: o The Windows Runtime can be called from either JavaScript or managed code. o Windows Runtime objects can be passed back and forth between the two. o Events can be handled from either side. o The ways you use Windows Runtime types in the two environments differ in some details, because JavaScript and the .NET Framework support the Windows Runtime differently.
  • 20. Windows Runtime Components Rules  You can throw any exception type that is included in the .NET for Windows Store apps - supported APIs.  You can't declare your own public exception types in a Windows Runtime component.  The way the exception appears to the caller depends on the way the calling language supports the Windows Runtime. o In JavaScript, the exception appears as an object in which the exception message is replaced by a stack trace. o In C++, the exception appears as a platform exception.
  • 21. demo
  • 22. Windows Runtime Components Rules  You can return a managed type, created in managed code, to JavaScript as if it were the corresponding Windows Runtime type. o When a managed type implements multiple interfaces, JavaScript uses the interface that appears first in the list. o If you pass an unassigned JavaScript variable as a string argument, what you get is the string "undefined".
  • 23. demo
  • 24. Windows Runtime Components Rules  You can declare events by using the standard .NET Framework event pattern or other patterns used by the Windows Runtime. o When you expose an event in the Windows Runtime, the event argument class inherits from System.Object. It doesn't inherit from System.EventArgs, as it would in the .NET Framework, because EventArgs is not a Windows Runtime type. o If you declare custom event accessors for your event, you must use the Windows Runtime event pattern. Custom events and event accessors in Windows Runtime Components
  • 25. demo
  • 26. Windows Runtime Components Rules  To implement an asynchronous method in your component, add "Async" to the end of the method name and return one of the Windows Runtime interfaces that represent asynchronous actions or operations: o IAsyncAction o IAsyncActionWithProgress<TProgress> o IAsyncOperation<TResult> o IAsyncOperationWithProgress<TResult, TProgress>
  • 27. Windows Runtime Components Rules  For asynchronous actions and operations that do not support cancellation or progress reporting, you can use the AsAsyncAction or AsAsyncOperation<TResult> extension method to wrap the task in the appropriate interface.
  • 28. demo
  • 29. Understand the Cost  Creating Windows Runtime Components using managed languages is a powerful feature.  It’s important to understand the cost when you’re using it in projects: o Windows Store apps built using native code don’t require the CLR to run. o The code written for the managed Windows Runtime Component will be compiled just-in-time (JIT). o The GC might pause your app while it’s performing work.
  • 30. When to Create Managed Windows Runtime Components  When to Create Managed Windows Runtime Components: o Consumable from all of the Windows Store languages. o Your team is more experienced in C# or Visual Basic than in C++ o You have existing algorithms written in a managed language o …
  • 31. When to Create Managed Windows Runtime Components  If you are creating a component for use only in Windows Store apps with Visual Basic or C#, and the component does not contain Windows Store controls, consider using the Class Library (Windows Store apps) template instead of the Windows Runtime Component template !!!  Alternatives for Managed Projects: o Class library for Windows Store o Portable Class Library o Extension SDK
  • 32. Q&A
  • 33. Links Creating Windows Runtime Components in C# and Visual Basic Walkthrough: Creating a simple component in C# or Visual Basic and calling it from JavaScript. Windows Runtime Components in a .NET World
  • 34. NetMF@Work 31 Maggio 2013 ore 09:00 Sede Microsoft Via Avignone 10, Roma Un’intera giornata per parlare di .NET Micro Framework e .NET Gadgeteer, dall’introduzione alla realizzazione di soluzioni IoT reali per un mondo di device interconessi
  • 35. feedback 10 Blog http://mircovanini.blogspot.com Email info@proxsoft.it Web www.proxsoft.it Twitter @MircoVanini Contatti o feedback su: • http://xedotnet.org/feedback o codice feedback: • ????