Introduction to Windows Mobile Development Daniel Moth Developer and Platform Group Microsoft UK http://www.danielmoth.com/blog
Same skills, same tools.net Visual Studio
AGENDA Same tools, same skills, same code.net Differences of NETCF with Full FX The Windows Mobile platform Platform-to-Code Cross-platform assets Windows Mobile Managed APIs
.NET Through The Ages 2002 2003 2005 2006 200? Tool (Visual Studio) VS.NET 2002 VS.NET 2003 VS2005 VS2005 Orcas Language(s) C# v1.0 VB.NET (v7.0) C# v1.1 VB.NET (v7.1) C# v2.0 VB (v8.0) as before C# v3.0 VB9 Framework Libraries NetFx v1.0 NetFx v1.1 (NETCF v1.0) NetFx v2.0 (NETCF v2.0) NetFx v3.0 NetFx v3.5 (NETCF v3.5) Engine (CLR) CLR v1.0 CLR v1.1 (CF CLR v1.0) CLR v2.0 (CF CLR v2.0) as before as before (CF CLR v3.5)
.NET Compact Framework Same IDE Visual Studio Same language features VB and C# only Smaller class library framework Approximately 1/20 th Compact CLR For more info: http://www.danielmoth.com/blog/2005/11/getting-started-with-net-compact.html
Install VS2005 Standard
Framework Compactness No... ASP.NET server Runtime hosting Code access security Binary serialization Reflection.Emit Codedom Configuration Also No... WPF WF LINQ to SQL LINQ to Entities Trimmed namespaces (XSLT), classes (Button.Image), missing method overloads, etc.
Classes Specific to NETCF v1.0 Microsoft.WindowsCE.Forms InputPanel, MessageWindow/Message System.Net.IrDA IrDAXXX EndPoint, Client, DeviceInfo, Listener System.Data.SqlServerCE SqlCeXXXX Command, CommandBuilder, Connection, DataAdapter, DataReader, Engine, Error, ErrorCollection, Exception, Parameter, RemoteDataAccess, Replication, Transaction
Classes Specific to NETCF v2.0 Microsoft.WindowsCE.Forms HardwareButton MobileDevice.Hibernate SystemSettings.ScreenOrientation.WinCEPlatform in v3.5 DocumentList Notification LogFont Microsoft.WindowsMobile.DirectX.Direct3D SqlCeResultSet For more info: http://www.danielmoth.com/blog/2005/08/not-strict-subset.html
Pictorial View of Versions Device Choices 2000 2002 2003 2003 Second Edition Windows Mobile 5 Core OS WinCE 3.0 WinCE 3.0 WinCE 4.2 WinCE 4.2 WinCE 5.0 evc 3 (C++) evc 3 (C++) evc 3 (C++) evc 3 (C++) Better evb 3 (VB) evb 3 (VB) evc 4 (C++) evc 4 (C++) Development VS.NET 2003 VS.NET 2003 VS 2005 (C#, VB.NET) (C#, VB.NET) (C#, VB.NET, C++) MFC 3.0 MFC 3.0, ATL 3.0.NET CF.NET CF SP2.NET CF 2.0 MFC 8.0, ATL 8.0 Richer Platform Capabilities Win32, POOM Active Sync Connection Mgr MAPI OBEX Telephony Enhanced Emulator Configuration Mgr, Bluetooth, SMS VGA (PPC) QVGA (SP) Square Landscape Broad managed code support Notification broker, Location, Camera, SQL CE, D3DM
Windows Mobile 6 Still based on Windows CE 5.0 New Naming scheme Pocket PC -> Classic Pocket PC Phone Edition -> Professional Smartphone -> Standard Improvements for business and consumer users For developer NETCF 2.0 SP1 in ROM Strong Windows Mobile 5.0 compatibility Device Emulator v2.0 + Cellular Emulator + other tools
Windows Mobile vs. Desktop Input Methods Form/Dialog size Navigation between applications App/Form Closing Take Over the Device don t! File System Memory (resource) Constraint Deployment For more info: http://www.danielmoth.com/blog/2005/01/desktop-to-ppc-part.html
I have to understand the platform! Soft Keys Input Methods Smart minimize Wait Cursor
Cross-Platform Assets Don t try your desktop binaries on device TypeLoadException, MissingMethodException Different PKTs Retargetable NETCF binaries can be executed on PC System.Environment.OSVersion.Platform Conditional Compilation Two projects, two outputs, one set of code files Build platform-specific binaries from same source For more info: http://www.danielmoth.com/blog/2004/09/share-code-if-fullframe_17.html
I can leverage my existing code!
Windows Mobile 5.0 / 6 Windows Mobile managed APIs Part of the platform, not part of NETCF Can be used by all versions of the NETCF WindowsMobile.PocketOutlook Edit Contacts, Appointments, and Tasks Control the Messaging application Send SMS and e-mail messages Intercept incoming SMS messages WindowsMobile.Status Query 100+ system properties Get notified of changes WindowsMobile.Configuration Configuration Manager WindowsMobile.Telephony Initiate phone calls WindowsMobile.Forms Contact Picker Dialog Picture Picker Dialog Camera Capture Dialog For more info: http://www.danielmoth.com/blog/2005/07/microsoftwindowsmobile.html
Device-specific libraries State & Notification Broker POOM
Summary Mobility is taking off rapidly! Be part of the game Get a Windows Mobile device Write NETCF applications
Resources Blogs, e.g. Mine http://www.danielmoth.com/blog Newsgroups http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.p ublic.dotnet.framework.compactframework Forums http://forums.microsoft.com/msdn/default.aspx?forumgroupid=11 Libraries Mobile Client Software Factory http://msdn.microsoft.com/mobileclientfactory SDF from OpenNETCF http://www.opennetcf.org/sdf/
Book Soon to be released From Microsoft Press Mobile Development Handbook co-authored with Peter Foot and Andy Wigley http://www.danielmoth.com/blog
2007 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.
Backup Slides Advanced topics
Compact CLR Garbage Collector JIT Mark and sweep (not generational) Three phases: Simple, Compact, Full Triggered by: Allocation failure App goes to background 1MB allocation in current versions (750KB in v1.0) Pitching No ngen For more info: http://www.danielmoth.com/blog/2004/12/jit.html
Learn from Smartphone Model Entirely Keyboard driven D-Pad (Left, Right, Up, Down, Enter) Good use of Soft Keys are crucial Controls are stacked Label, LinkLabel, CheckBox, ComboBox, TextBox, DateTimePicker TabIndex, TabStop...or full screen ListView, TreeView, DataGrid
Common Language Runtime Where does garbage come from? Unnecessary string copies Strings are immutable String manipulations (Concat(), etc.) cause copies Use StringBuilder http://weblogs.asp.net/ricom/archive/2003/12/02/40778.aspx String result = ""; StringBuilder result = new StringBuilder(); for (int i=0; i<10000; i++) { result += ".NET Compact Framework"; result += " Rocks!"; } for (int i=0; i<10000; i++){ result.append( ".NET Compact Framework"); result.append(" Rocks!"); }
.stat counter total last datum n mean min max Total Program Run Time (ms) 11843 - - - - - App Domains Created 1 - - - - - App Domains Unloaded 1 - - - - - Assemblies Loaded 2 - - - - - Classes Loaded 175 - - - - - Methods Loaded 198 - - - - - Closed Types Loaded String result 0 = - ""; - - - - Closed Types Loaded per Definition 0 0 0 0 0 0 Open Types Loaded 0 - - - - - Closed Methods for Loaded (int i=0; 0 i<10000; - - -i++) - {- Closed Methods Loaded per Definition 0 0 0 0 0 0 Open Methods Loaded 0 - - - - - Threads in Thread Pool - 0 2 0 0 1 Pending Timers - 0 2 0 0 1 Scheduled Timers 1 - - - - - Timers Delayed by Thread Pool Limit 0 - - - - - Work Items Queued result += 1 " Rocks!"; - - - - - Uncontested Monitor.Enter Calls 2 - - - - - Contested Monitor.Enter Calls 0 - - - - - Peak Bytes Allocated (native + managed) 3326004 - - - - - Managed Objects } Allocated 60266 - - - - - Managed Bytes Allocated 5801679432 28 60266 96267 8 580020 Managed String Objects Allocated 20041 - - - - - Bytes of String Objects Allocated 5800480578 - - - - - Garbage Collections (GC) 4912 - - - - - Bytes Collected By GC 5918699036 1160076 4912 1204946 597824 1572512 Managed Bytes In Use After GC - 580752 4912 381831 8364 580752 Total Bytes In Use After GC - 1810560 4912 1611885 1097856 1810560 GC Compactions 0 - - - - - Code Pitchings 0 - - - - - Calls to GC.Collect 0 - - - - - GC Latency Time (ms) 686 0 4912 0 0 16 Pinned Objects 0 - - - - - Objects Moved by Compactor 0 - - - - - Objects Not Moved by Compactor 0 - - - - - Objects Finalized 1 - - - - - Boxed Value Types 3 - - - - - Process Heap - 278 235 2352 68 8733 Short Term Heap - 0 278 986 0 10424 JIT Heap - 0 360 12103 0 24444 App Domain Heap - 0 1341 46799 0 64562 GC Heap - 0 35524 2095727 0 3276800 Native Bytes Jitted 22427 140 98 228 68 1367 Methods Jitted 98 - - - - - Bytes Pitched 0 0 0 0 0 0 Methods Pitched 0 - - - - - Method Pitch Latency Time (ms) 0 0 0 0 0 0 Exceptions Thrown GC latency 0 - - - - - Platform Invoke Calls 0 - - - - - Run time 173 sec result += ".NET Compact Framework"; Managed String Objects Allocated 20040 Garbage Collections (GC) 4912 Bytes of String Objects Allocate 5,800,480,574 Bytes Collected By GC 5,918,699,036 107128 ms
.stat counter total last datum n mean min max Total Program Run Time (ms) 11843 - - - - - App Domains Created 1 - - - - - App Domains Unloaded 1 - - - - - Assemblies Loaded 2 - - - - - Classes Loaded 175 - - - - - Methods Loaded 198 - - - - - Closed Types Loaded 0 - - - - - Closed Types Loaded per Definition 0 0 0 0 0 0 Open Types Loaded 0 - - - - - Closed for Methods Loaded (int i=0; i<10000; 0 - - i++){ - - - Closed Methods Loaded per Definition 0 0 0 0 0 0 Open Methods Loaded 0 - - - - - Threads in Thread Pool - 0 2 0 0 1 Pending Timers result.append(".net - 0 2 Compact 0 0 1 Scheduled Timers 1 - - - - - Timers Delayed by Thread Pool Limit 0 - - - - - Work Items Queued Framework"); 1 - - - - - Uncontested Monitor.Enter Calls 2 - - - - - Contested Monitor.Enter Calls 0 - - - - - Peak Bytes Allocated (native + managed) 3326004 - - - - - Managed Objects Allocated result.append(" 60266 - Rocks!"); - - - - Managed Bytes Allocated 5801679432 28 60266 96267 8 580020 Managed String Objects Allocated 20041 - - - - - Bytes } of String Objects Allocated 5800480578 - - - - - Garbage Collections (GC) 4912 - - - - - Bytes Collected By GC 5918699036 1160076 4912 1204946 597824 1572512 Managed Bytes In Use After GC - 580752 4912 381831 8364 580752 Total Bytes In Use After GC - 1810560 4912 1611885 1097856 1810560 GC Compactions 0 - - - - - Code Pitchings 0 - - - - - Calls to Managed GC.Collect String Objects 0 - Allocated - - - - 56 GC Latency Time (ms) 686 0 4912 0 0 16 Pinned Objects 0 - - - - - Objects Moved by Compactor 0 - - - - - Objects Not Moved by Compactor 0 - - - - - Objects Finalized 1 - - - - - Boxed Value Types 3 - - - - - Garbage Collections (GC) Process Heap - 278 235 2352 68 8733 2 Short Term Heap - 0 278 986 0 10424 JIT Heap - 0 360 12103 0 24444 App Domain Heap - 0 1341 46799 0 64562 GC Heap - 0 35524 2095727 0 3276800 Native Bytes Jitted 22427 140 98 228 68 1367 Methods GC Jitted Latency 98 - - - - - Bytes Pitched 0 0 0 0 0 0 Methods Pitched 0 - - - - - Method Pitch Latency Time (ms) 0 0 0 0 0 0 Exceptions Thrown 0 - - - - - Platform Invoke Calls 0 - - - - - Run time 0.1 sec StringBuilder result = new StringBuilder(); Bytes of String Objects Allocated 2097718 Bytes Collected By GC 1081620 21 ms