Microsoft® Mobile Development Handbook

Book description

Learn the essentials for developing mobile applications for any Windows-based mobile device. Focusing on proven techniques and practices, this guide addresses the real-world needs of experienced Microsoft Windows® mobile developers. Users are growing increasingly dependent on mobile devices, and with innovations that make it easy to manage data synchronization, this proliferation will continue. Developers need to respond to this evolution with more than simple adaptations of the user interface—they need to implement mobile solutions for most of their applications. From expert authors with years of real-world experience, this book addresses this evolution, covering key mobile-development topics, including design, debugging, deployment, performance optimization, security, and globalization. It also covers mobile applications that use Microsoft .NET Compact Framework 2.0, Microsoft SQL Server™ 2005 Everywhere Edition, and Microsoft Windows Mobile® 5.0, running on devices such as Pocket PCs and Windows Mobile Smartphones. In addition, it includes extensive code samples in Microsoft Visual C#®, with additional code sample in Microsoft Visual Basic® on the book’s companion Web site.

Table of contents

  1. Microsoft® Mobile Development Handbook
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. Foreword
    3. Acknowledgments
    4. Introduction
      1. Who This Book Is For
      2. How This Book Is Organized
      3. System Requirements
      4. Configuring SQL Server 2005 Express Edition
      5. Code Samples
      6. Support for This Book
        1. Questions and Comments
    5. I. The Essentials of Mobile Application Development
      1. 1. .NET Compact Framework—a Platform on the Move
        1. Getting Started with Mobile Application Development in Visual Studio
          1. Choosing the Version of Visual Studio
          2. Other Development Software You Need
          3. Choosing Your Platform: Pocket PC, Smartphone, or Windows CE?
          4. The Difference Between Windows CE and Windows Mobile
            1. The Windows CE Operating System
            2. Windows Mobile Operating Software
            3. Choosing Between Windows Mobile and Windows CE
            4. Programming API Differences
          5. Choosing the .NET Compact Framework Version
            1. .NET Compact Framework Service Packs
        2. Understanding the Differences Between the .NET Framework 2.0 and .NET Compact Framework 2.0
          1. Application Configuration Files
          2. ClickOnce
          3. Ngen.exe
          4. Remoting
          5. Serialization
          6. Printing
          7. Web Forms
        3. Understanding the Differences Between .NET Compact Framework Version 1.0 and Version 2.0
          1. Windows Forms
          2. Display and Layout Management
            1. Docking and Anchoring
            2. Automatic Scrollbars
            3. Screen Resolution Handling
            4. Tab Support and Keyboard Management
          3. Data
          4. Communications
          5. COM Interop
          6. Graphics Programming
          7. Security
          8. Threading
          9. Performance Monitoring
        4. Introducing .NET Compact Framework Version 3.5
        5. Using Community Resources
          1. Microsoft patterns & practices Mobile Application Blocks
          2. OpenNETCF Smart Device Framework
        6. Summary
      2. 2. Building a Microsoft Windows Forms GUI
        1. Understanding Windows Forms Version 2.0 Enhancements
        2. Using the Same Workflow as for Developing Desktop Applications
        3. Mapping Device Screens to Device Forms
          1. Screen Layout
          2. Closing a Form
          3. Form Navigation
            1. Ensuring That an Application Shows Only Once in the Running Programs List
        4. Exploring Important Windows Forms Controls
          1. Panel
          2. TabControl
          3. Menu (Soft Keys), ToolBar
          4. Microsoft.WindowsCE.Forms
            1. DocumentList (Pocket PC Only)
            2. Notification (Pocket PC Only)
            3. Other Classes
          5. Creating Your Own Controls
        5. Handling Input
          1. Taps
          2. SIP and Hardware QWERTY Keyboard
          3. Hardware Keys
        6. Considering the Physical Screen
          1. Orientation (and Size)
          2. Resolution
          3. Microsoft patterns & practices Orientation-Aware Control
            1. Using the Orientation-Aware Control
              1. Using the Orientation-Aware Control
          4. Alternative Design
        7. Developing for Smartphones
          1. Control Behaviors
          2. Navigation Paradigm
          3. InputModeEditor
          4. IntelliSense for Smartphone Projects
        8. Developing for Windows CE–Powered Devices
        9. Summary
      3. 3. Using SQL Server 2005 Compact Edition and Other Data Stores
        1. Using SQL Server 2005 Compact Edition Databases
          1. Creating a Database Using Visual Studio 2005
            1. Options for Database Security
          2. Creating a Database Using SQL Server 2005 Management Studio
          3. Connecting to an Existing Database
          4. Creating Tables, Indexes, and Foreign Keys
            1. Creating a Table
            2. Creating a Foreign Key
            3. Creating an Index
          5. Deciphering SqlCeExceptions
        2. Creating Connections to Data in Your Project
          1. Creating a Project Data Source
          2. Designing and Programming Strongly Typed DataSets and SqlCeResultSets
            1. Which Data Source: DataSet or SqlCeResultSet?
            2. Working with Strongly Typed DataSets and SqlCeResultSets
            3. Fixing the SqlCeResultSet
            4. Enabling Insert, Update, and Delete in Strongly Typed DataSets and SqlCeResultSets
            5. Using Strongly Typed DataSets and SqlCeResultSets with Queries That Use Joins
              1. Creating a Project Data Source That Makes a Complex Query
            6. Taking Advantage of Indexes with the SqlCeResultSet
        3. Building a Data-Bound GUI
          1. Building a Quick UI Using the Visual Tools
            1. Generating Data Forms
              1. Generating Data Forms
          2. Programming the BindingSource Control
            1. Why the BindingSource is a good thing
            2. Adding Records to a Record Set Using BindingSource
            3. Navigating Through a Record Set Using a BindingSource
          3. Data Binding Details Forms
            1. Creating Your Own Details Forms
            2. Accepting and Canceling Updates with EndEdit and CancelEdit
            3. Getting at the Underlying DataRow from the BindingSource
          4. Data Binding with the SqlCeResultSet
          5. Advanced Data Binding
            1. Data-Binding Combo Boxes to a Lookup Table
            2. Creating a Master–Detail GUI
          6. Formatting Data in DataGrid Controls
        4. Persisting Data Without a Database
          1. Serializing DataSet Objects
          2. Serializing Objects
            1. Serializing System.Color
        5. Summary
      4. 4. Catching Errors, Testing, and Debugging
        1. Connecting to a Target
          1. Device
          2. Emulator
          3. Best Choice
        2. Compile-Time Errors
        3. Exception Handling: Same as the Full .NET Framework
        4. Runtime Exceptions
          1. Diagnosing the Cause of the Exception
          2. It Is Your Fault
          3. Avoiding Exceptions Getting Thrown
          4. Handle the Exception and Recover Appropriately
          5. Protecting the Boundaries (or Global Exception Handling, the Hard Way)
        5. Global Exception Handling
          1. GEH on the Full .NET Framework
          2. GEH in .NET Compact Framework 1.0
          3. GEH in .NET Compact Framework 2.0
          4. GEH Choice: Single-Method vs. Multiple-Method Approach
            1. Informing the User and Getting the Log Files Back
        6. Some Exceptions Worthy of Further Mention
          1. WebException
          2. SocketException
          3. SqlCeException
          4. InvalidOperationException
          5. MissingMethodException
          6. MissingManifestResourceException
          7. TypeLoadException
        7. The Log Files
          1. Loader Log
          2. Interop Log
          3. Network Log
          4. Error Log
          5. Finalizer Log (Version 3.5)
          6. Remote Performance Monitor
        8. Instrumentation
          1. Breakpoints
          2. Tracepoints
          3. Debug.WriteLine
          4. Tracing to File
        9. Unit Testing
          1. Community Project
          2. Deploy to My Computer
          3. Patterns and Practices
          4. Visual Studio Code Name "Orcas"
        10. Summary
      5. 5. Understanding and Optimizing .NET Compact Framework Performance
        1. What Every Developer Should Know
        2. Understanding the Compact CLR Engine
          1. JIT Compiler
            1. Inlining
            2. Virtual Methods
          2. Garbage Collector
          3. Version 1.0 to Version 2.0 Improvements
        3. .NET Compact Framework Performance Statistics
          1. Activating Performance Counters
          2. Viewing the Data
          3. Performance Counter Descriptions
            1. Loader
            2. Generics
            3. Locks and Threads
            4. GC
            5. Memory
            6. JIT
            7. Exceptions
            8. Interop
            9. Networking
            10. Windows.Forms
          4. Remote Performance Monitor
            1. Connecting to the Device
            2. Collecting Live Counters
            3. Using PerfMon
        4. Measuring Performance Programmatically
        5. Performance Guidance
          1. Tips and Tricks
            1. Improve Start-Up Time
            2. Strings, XML, and Data
            3. Math
            4. Reflection
            5. Collections
            6. Overriding System.Object Methods
          2. Parting Thoughts
        6. Summary
      6. 6. Completing the Application: Packaging and Deployment
        1. Implementing Help
          1. Creating HTML-Based Help
          2. Starting Help Topics from Code
          3. Master Table of Contents
          4. Help on Smartphone Devices
        2. Locking Down Your Application
          1. Kiosk Mode
          2. Hardware Buttons
          3. Locking Down the User Interface
          4. Third-Party Solutions
        3. Deploying the Runtime
        4. Building a Device Installer
          1. Visual Studio Installer Tools
          2. Device Installer Project Type
          3. Adding Files and Setting Targets
          4. Adding Shortcuts
          5. Writing Registry Settings
          6. Compression
        5. Security Policies and Code Signing
          1. Signing Your Code
          2. Design Guidelines and Mobile2Market
        6. The Global Assembly Cache
          1. Strong Naming Your Assemblies
          2. When and How to Use the Global Assembly Cache
          3. Native CESetup.dll
          4. Testing Your .cab File
        7. Building a Desktop Installer
          1. Adding Your .cab Project
          2. Adding Other Application Files
          3. Automating the Device-Side Installation
          4. Adding a Custom Installer Action
          5. Running the Installer
        8. Summary
    6. II. Solutions for Challenges in Mobile Applications
      1. 7. Exchanging Data with Backend Servers
        1. Architecting a Data Synchronization Application
          1. Designing for the Mostly Disconnected Client
          2. Designing for Stale Data
          3. Choosing the Synchronization Technique
        2. Using Web Services for Data Synchronization
          1. Authenticating Web Services Clients
            1. Custom Authentication with SOAP Headers
          2. Using Web Services on Occasionally Connected Clients
            1. Getting Started with the Disconnected Service Agent
            2. Setting the Configuration File
            3. Generating the Disconnected Service Agent Proxy
            4. Initializing the Request Manager
            5. Queuing a Request
            6. Handling the Callback
          3. Compressing Web Service Payload
            1. Coding a SOAP Extension for Compression
            2. Using the CompressionSoapExtension
        3. Accessing SQL Server Directly by Using SqlClient
          1. Understanding Differences from the Desktop .NET Framework
            1. Only TCP/IP Connections Are Supported
            2. Implementing Transactions
            3. Establishing Connections
          2. Programming System.Data.SqlClient
            1. Setting the Connection String
          3. Using Transactions in the .NET Compact Framework
        4. Synchronizing Data Using SQL Server 2005 Compact Edition Remote Data Access
          1. Understanding RDA Pull and Push
            1. Understanding RDA Pull and Push
            2. RDA Server Setup
            3. Pulling Data into a Local Database
            4. Making Changes to a Pulled Table
            5. Pushing Changes Back to the Remote Database
            6. Running Commands on the Remote Database
            7. Troubleshooting RDA
        5. Replicating Data Using SQL Server Merge Replication
          1. SQL Server CE Merge Replication Architecture
          2. Setting Up Merge Replication
            1. Setting Up the Publication
            2. Setting Up the Web Server
            3. Merge Replication Security
          3. Programming Merge Replication
            1. Adding a Subscription
            2. Synchronization
            3. Troubleshooting Merge Replication
        6. Summary
      2. 8. Networking
        1. Understanding Complications of Networking and Mobile Devices
        2. Using Web Services
        3. Understanding System.Net
          1. WebRequest
          2. Sockets
            1. Differences Between the Desktop Framework and the Compact Framework
            2. SocketException
            3. Using Sockets
            4. A Simple Server
            5. Client Connections
        4. Using IrDA and Bluetooth
        5. Using Serial Ports
          1. Virtual Serial Ports
        6. Understanding System.Messaging
          1. Installing MSMQ
            1. Set Up a Private Queue
            2. Transaction Support
            3. Formatters
            4. Queuing Messages from the Device
        7. Summary
      3. 9. Getting Connected
        1. Understanding Connections on Windows Mobile
        2. Using Desktop Passthrough
        3. Making Voice and Data Calls
          1. Voice Calls
            1. Making a Voice Call on Windows Mobile 2003
            2. Making a Voice Call on Windows Mobile 5.0 and Later
          2. Establishing Data Calls
            1. Connection Manager
            2. Remote Access Service
          3. Microsoft patterns & practices Network Monitor Application Block
        4. Enabling and Disabling Adapters
          1. Cellular Phones
          2. WiFi
          3. Bluetooth
        5. SMS Interception
        6. Summary
      4. 10. Security Programming for Mobile Applications
        1. Implementing Good Security
          1. Performing Security Reviews
          2. Why You Should Not Hard-Code Secrets
          3. Understanding Good—and Bad—Techniques for Hiding Secrets
          4. Good Security Requires User Input
        2. Storing Credentials and Other Secrets Securely
          1. Protecting Data in SQL Server CE Databases
          2. Programming a Secure Solution by Using the Microsoft patterns & practices Application Blocks
            1. Defining the Configuration File
            2. Encrypting the Configuration File
            3. Creating User-Specific Encrypted Keys
            4. Creating Tokens for User Authentication
            5. Authenticating the User and Decrypting the Config File on the Device
            6. Handling Changed or Forgotten Passwords
        3. Encrypting Data
          1. Encrypting Using the AES Symmetric Algorithm
            1. Deriving the Key from a Text String
            2. Encrypting
            3. Decrypting
          2. Encrypting Using the RSA Asymmetric Algorithm
            1. Generating RSA Keys
            2. Keeping Private Keys Secure
            3. Encrypting Using the RSA Public Key
            4. Decrypting Using the RSA Private Key
        4. Securing Network Connections
          1. Root Certificates Installed on a Windows Mobile–Powered Device
          2. Using a Self-Signed Certificate
            1. Validating a Server SSL Certificate in Code
        5. Validating User Input
        6. Perimeter Security: Securing Access to the Device
          1. Remote Management Using Exchange Server 2003 SP2 and the MSFP
        7. Signing Applications
          1. Understanding Windows Mobile Security Policy
            1. Privileged, Unprivileged, and Unsigned Applications
            2. Trusted and Normal Execution Modes
            3. One-Tier and Two-Tier Security
            4. Security Policies
            5. Security Configurations
            6. Viewing and Provisioning Security Configurations with the Security Manager PowerToy
          2. Provisioning Windows Mobile–Powered Devices
            1. Preventing Unsigned Applications from Running
        8. Summary
      5. 11. Threading
        1. Why Use Threads?
        2. Understanding Underlying Fundamentals
          1. Windows CE
          2. System.Threading
        3. Maintaining a Responsive User Interface
          1. Message Pump
          2. Long-Running Tasks
          3. Demonstration Example
          4. Nonideal Solutions
          5. Using a Thread to Solve the Problem
            1. System.Windows.Forms.Timer
            2. Thread.Join
            3. Control.Invoke
          6. BackgroundWorker
        4. Synchronizing Thread Activities and Access to Data
          1. Race Conditions
          2. Monitor
          3. Thread Safe
          4. Deadlocks Revisited
          5. ManualResetEvent
        5. ThreadPool
        6. Understanding Threading and Application Shutdown
          1. Background Threads
          2. Thread Termination
        7. Using .NET Timers
        8. Summary
      6. 12. Graphics Programming
        1. Drawing Images, Text, and Shapes
          1. Understanding Painting Basics
          2. Drawing Images
          3. Scaling Images
          4. Painting the Background
          5. Painting Shapes and Text
            1. Wrapping Text
          6. Drawing Lines
        2. Handling Different Resolutions
        3. Rotating Text
        4. Reducing Flicker by Using Double Buffering
          1. Overriding OnPaintBackground
        5. Using Advanced Formatting Techniques
          1. Drawing Using Gradient Fill
          2. Drawing Images with a Transparent Background
          3. Drawing Using Alpha Blending
        6. Summary
      7. 13. Direct3D Mobile
        1. Getting Started with Direct3D
          1. Using Direct3D in Your Programs
          2. The Direct3D Device
          3. The Draw Process
          4. Getting a Direct3D Program Running
        2. Working in Three Dimensions
          1. Rendering a Triangle
          2. Understanding Coordinates and Viewing
          3. Moving an Object in Three Dimensions
          4. From Programmer to Film Director
          5. Matrices
          6. Perspective and Transformations
          7. Transformations and Animations
          8. Adding More Complicated Transformations
          9. Adding Textures
          10. Creating More Complex Objects
          11. Drawing Multiple Items
          12. Lighting
            1. Vertices and Normals
            2. Lights Setup
          13. Meshes
          14. Lighting and Materials with Meshes
            1. Ambient Light
            2. Diffuse Light
        3. Direct3D on Mobile Devices
          1. Direct3D and Events
            1. Device Reset
          2. Managing Orientation Change
          3. Direct3D Drawing Performance
          4. Handling Platform Diversity
          5. Battery Life
        4. Summary
      8. 14. Interoperating with the Platform
        1. Understanding Platform Invocation Services
          1. Marshaling
            1. MarshalAsAttribute
            2. Native Structures
          2. NativeMethods
          3. Media Example
          4. Callbacks into Managed Code
            1. MessageWindow
            2. Named Events
            3. Function Pointers
        2. Understanding COM Interop
          1. Importing COM Libraries
          2. Manually Defining Interfaces
            1. Interface Types
            2. COM Error Handling
            3. Specific Device Issues
            4. Structures with Unions
          3. ActiveX Controls
        3. Summary
      9. 15. Building Custom Controls
        1. Extending Existing Controls
          1. Overriding Events
        2. Creating Custom Controls
          1. UserControl
            1. Exposing Properties
            2. Exposing Events
          2. Control
            1. Double Buffering
            2. Screen Resizing
        3. Programming the Design-Time Experience
          1. Attributes
            1. DesktopCompatible
            2. Custom Property
            3. DefaultEvent
            4. EditorBrowsable
            5. Custom Property Types
            6. Class Diagrams
            7. Custom Metadata Assemblies
            8. Migrating Old Controls
          2. Adding to Visual Studio 2005 Toolbox
        4. Summary
      10. 16. Internationalization
        1. Understanding the Challenges of Globalization
        2. Culture
          1. CultureInfo
          2. Revisiting the Challenges
        3. Using Language Translation (or Localization)
          1. Creating Resource Files
          2. Reading from Resources
            1. Form's Localizable Property
          3. Locale-Specific Resources and Satellite Assemblies
          4. Actually Translating the Text
        4. Summary
      11. 17. Developing with Windows Mobile
        1. Pocket Outlook
          1. Personal Information Management
            1. PimItem
            2. Appointments
            3. Tasks
            4. Reminders
            5. Recurrence Patterns
            6. Contacts
            7. Custom Properties
          2. Messaging
            1. E-Mail
            2. SMS
        2. State and Notifications
        3. Pictures
          1. Camera
        4. GPS
        5. Configuration
          1. Configuring the Device Programmatically
          2. Deploying Configuration Settings
        6. Telephony
        7. Earlier Versions of Windows Mobile
        8. Summary
    7. III. New Developments
      1. 18. Introducing .NET Compact Framework Version 3.5 and Visual Studio Code Name "Orcas"
        1. Introducing .NET Compact Framework 3.5
        2. Introducing Visual Studio Code Name "Orcas"
        3. Developing Applications with .NET Compact Framework 3.5
          1. Programming Compact WCF
            1. Using E-Mail as a WCF Transport, and the Story of the Lunch Launcher
            2. Supported Connectivity for Compact WCF
            3. Programming WCF Using the BasicHTTPBinding
            4. Programming WCF Using the E-Mail Transport
          2. Programming Language Integrated Query
            1. Query Syntax
            2. Lambda Expressions
            3. Extension Methods
            4. Type Inference
            5. Anonymous Types
            6. LINQ to Objects
            7. LINQ to XML
            8. LINQ to DataSet
          3. Programming System.IO.Compression
        4. Unit Testing in Visual Studio Code Name "Orcas" Team System
          1. Writing Unit Tests in Visual Studio Code Name "Orcas"
          2. Running Unit Tests
        5. Summary
    8. Index
    9. About the Authors
    10. SPECIAL OFFER: Upgrade this ebook with O’Reilly

Product information

  • Title: Microsoft® Mobile Development Handbook
  • Author(s): Andy Wigley, Daniel Moth, Peter Foot
  • Release date: May 2007
  • Publisher(s): Microsoft Press
  • ISBN: 9780735623583