SlideShare a Scribd company logo
1 of 28
WAY AHEAD™
Native Development for Windows Phone
The Windows Runtime API and Modern C++
2
»Senior Software Engineer at ALK Technologies
»Led development effort to bring CoPilot GPS
navigation app to Windows Phone 8
» #4 Free Navigation App in Window Phone store
»Windows Phone Dev by day and night
» Released 6 of my own apps to Windows Phone store
»Blog: www.robwirving.com
»Twitter: @robwirving
Rob Irving
3
»History of Native on Windows Phone
»Why use Native?
»C++ 11
»Windows Runtime (WinRT)
»Component Extensions (C++/CX)
»Options in Visual Studio
»Sample Code
»Q & A
Agenda
4
»Lack of Native Development on WP7 hurt the
platform
» Lack of high-end games available on other platforms
» More difficult/impossible to port existing apps from
other platforms
»Support for Native Development is the single
largest change in the WP8 SDK
»Native Gaming and Middleware products
» Unity 3D, Havok, Cocos 2D, etc.
History of Native on Windows Phone
WAY AHEAD™
Why use Native?
6
»Reusability
» Existing code that you don’t want to rewrite
» Use of existing 3rd party libraries (SQLite)
»Portability
» Share code between Windows, iOS and Android
» Write once, use it everywhere
Why use Native?
7
»Game development with high-end graphics
» Direct3D on Windows and Windows Phone
» OpenGL on iOS and Android
»Performance
» Should not be viewed as the main reason to use C++
» Performance can be better using Native, but is often
exaggerated
Why use Native?
8
»Portability & Reusability in action
» ~1,000 Lines of C# for WP8
» ~7,000 Lines of new C++ and C++/CX
» ~800,000 Lines of existing C++ code
»~99% shared code between
Windows Phone, iOS and Android!
CoPilot GPS – Native Case Study
WAY AHEAD™
A brief introduction to Modern C++
C++ 11
10
1979
1983
1998 2011
History of C++
C++ began as an
enhancement
to C at Bell Labs
Originally named
‘C with Classes’
Renamed to C++
C++ ISO committee
defined C++ 98
No significant changes
to C++ for 13 years
C++ ISO committee
defined C++ 11
New features heavily
influenced by managed
languages like .NET
11
»Type inference (auto)
» Avoid explicitly declaring the type of a variable
» Similar to .NET ‘var’ keyword
»Lambdas
» Anonymous inline functions
C++ 11 Features
int num1 = 10;
double num2 = 2.5
auto num3 = num1 / num2;
std::vector<CityLocation> cities;
std::sort(begin(cities), end(cities), [](CityLocation a, CityLocation b)
{
return a.distance < b.distance;
});
12
»Strongly type enums
»Foreach-ish loop
C++ 11 Features
int numbers[] = {0, 1, 2, 3, 4, 5};
int sum = 0;
for(int& number : numbers)
{
sum += number;
}
enum class Fruit
{
Apple,
Banana,
Orange
};
if(meal.Fruit == Fruit::Banana)
// do Banana stuff
int fruitAbomination = Apple + Orange; // ERROR - Can’t do this anymore
WAY AHEAD™
Windows Runtime API
14
»Shared API between Windows Phone 8 and
Windows Store Apps
» Overlaps much of the existing Windows Phone .NET
API
» Not all APIs are available for both
» ~11,000 Windows Runtime
» ~2,800 for both
» ~600 Windows Phone Runtime
Windows Runtime API (WinRT)
15
»API is a COM-based Native API
»Accessible from C#, VB.NET and Component
Extensions (C++/CX)
» Also Javascript on Windows 8
»API definitions in Windows Metadata (.winmd)
files
» Similar format to .NET API definitions
Windows Runtime API (WinRT)
16
»Native / Managed Interop
» WinRT is the only supported method of interop
»The most painful parts of Native /Managed
interop are gone with Windows Runtime
» No P/Invoke
» No Marshalling
Native Interop is easy with WinRT
WAY AHEAD™
Component Extensions (C++/CX)
18
»Syntax and Library abstractions to interact with
COM based WinRT API
»Much easier to develop for compared to old
COM programming
Component Extensions (C++/CX)
19
»Syntactically similar to C++/CLI
» ‘ref’ and ‘sealed’ classes
» Reference pointers or ‘hats’ ^
Component Extensions (C++/CX)
public ref class Foo sealed
{
};
Foo^ foo = ref new Foo();
20
»Differences from C++/CLI
» No managed CLR
» No Garbage Collection, ref counted objects instead
» ref new instead of gcnew
» Pure C++ classes allowed in C++/CX classes
» Global ref ptr’s allowed
Component Extensions (C++/CX)
21
»Properties
» No value keyword
» Can’t have public get, private set
Component Extensions (C++/CX)
public ref class Foobar sealed
{
public:
property int Foo; // automatic/trivial property
property int Bar
{
int get() { return _bar; }
void set(int newBar)
{
if(newBar > 0)
_bar = newBar;
}
}
private:
int _bar;
};
22
»Events
» Very similar to .NET events
» Unsubscribe using token
Component Extensions (C++/CX)
MyClass::MyClass()
{
geoLocator = ref new Geolocator();
// subscribe
eventToken = geoLocator->PositionChanged +=
ref new TypedEventHandler<Geolocator^, PositionChangedEventArgs^>(this, &MyClass::OnPosChanged);
}
MyClass::~MyClass()
{
// unsubscribe
geoLocator->PositionChanged -= eventToken;
}
void MyClass::OnPosChanged(Geolocator^ geoLocator, PositionChangedEventArgs^ args)
{
auto geoPos = args->Position->Coordinate;
}
23
»XAML with Direct 3D
Options in Visual Studio
24
»Several Native Projects available
Options in Visual Studio
WAY AHEAD™
Visual Studio Demo
26
Additional Resources
Windows Phone 8 Development Internals
(Whitchapel, McKenna)
http://amzn.to/1a2989c
Modern C++ and Windows Store Apps
(Poduri)
http://amzn.to/GEW6Y4
27
»Channel 9 – channel9.msdn.com
» Build 2012 Sessions
channel9.msdn.com/Events/Build/2012/
» Build 2013 Sessions
channel9.msdn.com/Events/Build/2013/
» Going Native
channel9.msdn.com/Shows/C9-GoingNative
»C++ 11 Features in Visual C++ 11
blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx
Additional Resources
28
»Questions & Answers
»Slides will be posted to blog: robwirving.com
Thank You!

More Related Content

Similar to Native Development for Windows Phone 8

Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
C++ in windows phone apps
C++ in windows phone appsC++ in windows phone apps
C++ in windows phone appsMirco Vanini
 
Flutter vs. MAUI - what should you pick and why?
Flutter vs. MAUI - what should you pick and why?Flutter vs. MAUI - what should you pick and why?
Flutter vs. MAUI - what should you pick and why?Tobias Hoppenthaler
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Introduction of c++ course
Introduction of c++ courseIntroduction of c++ course
Introduction of c++ coursekritikasoni15
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroMohammad Shaker
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Richard Thomson
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
Cross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with XamarinCross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with Xamarinbryan costanich
 
Cross platform development
Cross platform developmentCross platform development
Cross platform developmentdftaiwo
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Eugene Kurko
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019UA Mobile
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopmentgillygize
 

Similar to Native Development for Windows Phone 8 (20)

Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
C++ in windows phone apps
C++ in windows phone appsC++ in windows phone apps
C++ in windows phone apps
 
Flutter vs. MAUI - what should you pick and why?
Flutter vs. MAUI - what should you pick and why?Flutter vs. MAUI - what should you pick and why?
Flutter vs. MAUI - what should you pick and why?
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Introduction of c++ course
Introduction of c++ courseIntroduction of c++ course
Introduction of c++ course
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
Session Four C#
Session Four C# Session Four C#
Session Four C#
 
Session 1 - c++ intro
Session   1 - c++ introSession   1 - c++ intro
Session 1 - c++ intro
 
Cross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with XamarinCross Platform Mobile Development with Xamarin
Cross Platform Mobile Development with Xamarin
 
Session4 csharp
Session4 csharpSession4 csharp
Session4 csharp
 
C# rocks
C# rocksC# rocks
C# rocks
 
Cross platform development
Cross platform developmentCross platform development
Cross platform development
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
State ofappdevelopment
State ofappdevelopmentState ofappdevelopment
State ofappdevelopment
 

Recently uploaded

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Recently uploaded (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

Native Development for Windows Phone 8

  • 1. WAY AHEAD™ Native Development for Windows Phone The Windows Runtime API and Modern C++
  • 2. 2 »Senior Software Engineer at ALK Technologies »Led development effort to bring CoPilot GPS navigation app to Windows Phone 8 » #4 Free Navigation App in Window Phone store »Windows Phone Dev by day and night » Released 6 of my own apps to Windows Phone store »Blog: www.robwirving.com »Twitter: @robwirving Rob Irving
  • 3. 3 »History of Native on Windows Phone »Why use Native? »C++ 11 »Windows Runtime (WinRT) »Component Extensions (C++/CX) »Options in Visual Studio »Sample Code »Q & A Agenda
  • 4. 4 »Lack of Native Development on WP7 hurt the platform » Lack of high-end games available on other platforms » More difficult/impossible to port existing apps from other platforms »Support for Native Development is the single largest change in the WP8 SDK »Native Gaming and Middleware products » Unity 3D, Havok, Cocos 2D, etc. History of Native on Windows Phone
  • 6. 6 »Reusability » Existing code that you don’t want to rewrite » Use of existing 3rd party libraries (SQLite) »Portability » Share code between Windows, iOS and Android » Write once, use it everywhere Why use Native?
  • 7. 7 »Game development with high-end graphics » Direct3D on Windows and Windows Phone » OpenGL on iOS and Android »Performance » Should not be viewed as the main reason to use C++ » Performance can be better using Native, but is often exaggerated Why use Native?
  • 8. 8 »Portability & Reusability in action » ~1,000 Lines of C# for WP8 » ~7,000 Lines of new C++ and C++/CX » ~800,000 Lines of existing C++ code »~99% shared code between Windows Phone, iOS and Android! CoPilot GPS – Native Case Study
  • 9. WAY AHEAD™ A brief introduction to Modern C++ C++ 11
  • 10. 10 1979 1983 1998 2011 History of C++ C++ began as an enhancement to C at Bell Labs Originally named ‘C with Classes’ Renamed to C++ C++ ISO committee defined C++ 98 No significant changes to C++ for 13 years C++ ISO committee defined C++ 11 New features heavily influenced by managed languages like .NET
  • 11. 11 »Type inference (auto) » Avoid explicitly declaring the type of a variable » Similar to .NET ‘var’ keyword »Lambdas » Anonymous inline functions C++ 11 Features int num1 = 10; double num2 = 2.5 auto num3 = num1 / num2; std::vector<CityLocation> cities; std::sort(begin(cities), end(cities), [](CityLocation a, CityLocation b) { return a.distance < b.distance; });
  • 12. 12 »Strongly type enums »Foreach-ish loop C++ 11 Features int numbers[] = {0, 1, 2, 3, 4, 5}; int sum = 0; for(int& number : numbers) { sum += number; } enum class Fruit { Apple, Banana, Orange }; if(meal.Fruit == Fruit::Banana) // do Banana stuff int fruitAbomination = Apple + Orange; // ERROR - Can’t do this anymore
  • 14. 14 »Shared API between Windows Phone 8 and Windows Store Apps » Overlaps much of the existing Windows Phone .NET API » Not all APIs are available for both » ~11,000 Windows Runtime » ~2,800 for both » ~600 Windows Phone Runtime Windows Runtime API (WinRT)
  • 15. 15 »API is a COM-based Native API »Accessible from C#, VB.NET and Component Extensions (C++/CX) » Also Javascript on Windows 8 »API definitions in Windows Metadata (.winmd) files » Similar format to .NET API definitions Windows Runtime API (WinRT)
  • 16. 16 »Native / Managed Interop » WinRT is the only supported method of interop »The most painful parts of Native /Managed interop are gone with Windows Runtime » No P/Invoke » No Marshalling Native Interop is easy with WinRT
  • 18. 18 »Syntax and Library abstractions to interact with COM based WinRT API »Much easier to develop for compared to old COM programming Component Extensions (C++/CX)
  • 19. 19 »Syntactically similar to C++/CLI » ‘ref’ and ‘sealed’ classes » Reference pointers or ‘hats’ ^ Component Extensions (C++/CX) public ref class Foo sealed { }; Foo^ foo = ref new Foo();
  • 20. 20 »Differences from C++/CLI » No managed CLR » No Garbage Collection, ref counted objects instead » ref new instead of gcnew » Pure C++ classes allowed in C++/CX classes » Global ref ptr’s allowed Component Extensions (C++/CX)
  • 21. 21 »Properties » No value keyword » Can’t have public get, private set Component Extensions (C++/CX) public ref class Foobar sealed { public: property int Foo; // automatic/trivial property property int Bar { int get() { return _bar; } void set(int newBar) { if(newBar > 0) _bar = newBar; } } private: int _bar; };
  • 22. 22 »Events » Very similar to .NET events » Unsubscribe using token Component Extensions (C++/CX) MyClass::MyClass() { geoLocator = ref new Geolocator(); // subscribe eventToken = geoLocator->PositionChanged += ref new TypedEventHandler<Geolocator^, PositionChangedEventArgs^>(this, &MyClass::OnPosChanged); } MyClass::~MyClass() { // unsubscribe geoLocator->PositionChanged -= eventToken; } void MyClass::OnPosChanged(Geolocator^ geoLocator, PositionChangedEventArgs^ args) { auto geoPos = args->Position->Coordinate; }
  • 23. 23 »XAML with Direct 3D Options in Visual Studio
  • 24. 24 »Several Native Projects available Options in Visual Studio
  • 26. 26 Additional Resources Windows Phone 8 Development Internals (Whitchapel, McKenna) http://amzn.to/1a2989c Modern C++ and Windows Store Apps (Poduri) http://amzn.to/GEW6Y4
  • 27. 27 »Channel 9 – channel9.msdn.com » Build 2012 Sessions channel9.msdn.com/Events/Build/2012/ » Build 2013 Sessions channel9.msdn.com/Events/Build/2013/ » Going Native channel9.msdn.com/Shows/C9-GoingNative »C++ 11 Features in Visual C++ 11 blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx Additional Resources
  • 28. 28 »Questions & Answers »Slides will be posted to blog: robwirving.com Thank You!

Editor's Notes

  1. So why use Native? Can anyone tell me some of the reasons why you might want to use Native Code instead of something like C# ? Performance is not the main reason