Introduction to
Windows Mobile Development
Daniel Moth
Developer and Platform Group
Microsoft UK
.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
.NET Through The Ages
2002
2003
2005
2006
200?
Tool
(Visual Studio)
VS .NET 2002
VS.NET 2003
VS2005
VS2005
“Orcas”
Language(s)
VB.NET (v7.0)
C# v1.0
VB.NET (v7.1)
C# v1.1
VB (v8.0)
C# v2.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
“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
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
Richer
Platform
Capabilities
.NET CF 2.0
MFC 8.0, ATL 8.0
Broad managed
code support
Notification broker,
Location, Camera,
SQL CE, D3DM
.NET CF SP2
VGA (PPC)
QVGA (SP)
Square
Landscape
.NET CF
Enhanced Emulator
Configuration Mgr,
Bluetooth, SMS
MFC 3.0, ATL 3.0
Active Sync
Connection Mgr
MAPI
OBEX
Telephony
MFC 3.0
Win32,
POOM
Better
Development
VS 2005
(C#, VB.NET, C++)
eVC 3
(C++)
eVC 4
(C++)
VS.NET 2003
(C#, VB.NET)
eVC 3
(C++)
eVC 4
(C++)
VS.NET 2003
(C#, VB.NET)
eVC 3
(C++)
eVB 3
(VB)
eVC 3
(C++)
eVB 3
(VB)
Core OS
WinCE 3.0
WinCE 3.0
WinCE 4.2
WinCE 4.2
WinCE 5.0
Device
Choices
Windows Mobile 5
2003
Second Edition
2003
2002
2000
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
For more info:
http://www.danielmoth.com/Blog/2005/01/desktop-to-ppc-part.html
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
Soft Keys
Input Methods
Smart minimize
Wait Cursor
“I have to understand the
platform!”
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
“I can leverage my
existing code!”
WindowsMobile.Configuration
Configuration Manager
WindowsMobile.Telephony
Initiate phone calls
WindowsMobile.Forms
Contact Picker Dialog
Picture Picker Dialog
Camera Capture Dialog
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
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
State & Notification Broker
POOM
Summary
Get a Windows Mobile device
Write NETCF applications…
Mobility is taking off rapidly!
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
Book
Soon to be released
http://www.danielmoth.com/Blog
From Microsoft Press
“Mobile Development Handbook”
© 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
Compact CLR
Garbage Collector
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)
JIT
Pitching
No ngen
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
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 = "";
for (int i=0; i<10000; i++) {
result +=
".NET Compact Framework";
result += " Rocks!";
}
StringBuilder result =
new StringBuilder();
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 0 - - - -
-Closed Types Loaded per Definition 0 0 0 0 0 0
Open Types Loaded 0 - - - -
-Closed Methods Loaded 0 - - - -
-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 1 - - - -
-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 0 - - - -
-Platform Invoke Calls
0 -
-
-
-
-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
GC latency
107128 ms
String result = "";
for (int i=0; i<10000; i++) {
result += ".NET Compact Framework";
result += " Rocks!";
}
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 Methods Loaded 0 - - - -
-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 1 - - - -
-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 0 - - - -
-Platform Invoke Calls