Visual C++ Smart Device Primer

Many developers shy away from embedded development for a number of reasons—difficulty in understanding the wide array of Windows CE/ Windows Mobile configurations, uncertainty about how to get started with an embedded project, and perceived difficulties in device debugging. This article aims to address all these issues, and get C++ developers familiar with the great opportunities that exist in life outside the desktop/ server environment.

Before digging into the mobile C++ development world, it is worth briefly looking at the managed alternatives. As with the desktop world, managed development is possible in the embedded world by using a cut-down version of the .NET Framework officially titled the Microsoft .NET Compact Framework. The .NET Compact Framework has been notoriously lacking in many of the features that exist in the main .NET Framework, and an old joke circa .NET Compact Framework 1 is that the Compact Framework is a wrapper around the System.NotImplementedException (and the fact that earlier versions of the Compact Framework did not include the NotImplementedException type highlighted how 'compact' it truly was).

Although the functionality available in the .NET Framework has significantly increased with each new version, and .NET Compact Framework 3.5 has some great features from the full version—like LINQ—included, two significant issues will continue to exist with the .NET Compact Framework for the foreseeable future. The first problem is the lag between the release of a Compact Framework version and its inclusion in the ROM image that a particular embedded device ships with. Windows Mobile 6 is the latest release of the CE/Mobile family, and it includes version 2 of the Compact Framework. When version 3.5 ships shortly, any application that uses it will need to ensure that target device has the 3.5 Framework installed; this chews up valuable memory on the device that could otherwise be used by other applications. For the majority of devices in production that are running Windows Mobile 5 or older, the situation is worse, because they are likely to ship only with the feature-poor version 1 of the Compact Framework. The second issue with the Compact Framework is a small range of features for interacting with the actual device on which the application is running. As with the main Windows version of the Framework, .NET is great for writing code for applications that run on top of the operating system, but for applications that want to have significant interaction with the newer and more esoteric features of the host OS, C# and Visual Basic.NET are poor alternatives to C++.

For many years, C++ developers producing server and desktop applications for Windows only had to worry about a single processor instruction set (x86) and a single SDK (the Win32 SDK), and although the advent of two distinct 64-bit processor architectures has slightly complicated the picture, life is still relatively simple for the developer. In contrast, the embedded world is markedly more complicated, with a great variety of processors, devices, and operating system builds that could potentially be targeted by a single code-base. Sitting on top of the wide variety of device form-factors is the Windows CE operating system, which has been officially renamed "Windows Embedded CE" in the recent 6.0 release. Windows CE consists of an operating system kernel and an array of optional components that a device OEM can configure to include in a particular build. Because of the wide variety of devices that Windows CE can support, an application developer will typically target a pre-defined build of Windows CE rather than attempting to provide support for all possible device configurations.

Windows Embedded CE 6.0, which was released in November 2006, has three Microsoft-defined platforms that a device OEM can choose to license for installation onto a particular device: Windows Mobile 6 Standard (which is the latest version of the platform formally known as Windows Mobile for Smartphone), Windows Mobile 6 Professional (formally known as Windows Mobile for Pocket PC Phone Edition), and Windows Mobile 6 Classic (formally known as Windows Mobile for Pocket PC). Windows Mobile Classic is customized for PDA devices that don't have any telephony functionality, such as the HP iPAQ. Windows Mobile Standard is for Windows phone devices that have a traditional phone-form factor that consists primarily of a non-touch screen and numeric keypad, and Windows Mobile Professional is for hybrid devices that have both phone and PDA functionality.

Although it may seem like a tedious exercise in nomenclature trudging through the previous and current versions of Windows CE platforms, understanding the various CE platforms is critical from a developer's perspective because there is an SDK for each corresponding platform. Each different platform has subtly different components and features that are available, and the correct SDK must be installed to target the appropriate device. For Windows Mobile 6, two separate SDKs are available—the Windows Mobile 6 Standard SDK that targets Windows Mobile Standard and the Windows Mobile 6 Professional SDK that targets Windows Mobile 6 Classic and Windows Mobile 6 Professional. So, thankfully, the choice of which SDK to use for which Windows Mobile 6 devices comes down to a simple decision point: Does the target device have a touch-screen? Both SDKs can be downloaded from the Microsoft Download Center, and will install with either Visual Studio 2005 or 2008.

Now that the groundwork has finally been laid, it's time to have a look at the C++ developer experience for a mobile application. The first task is to ensure that the Visual C++ Smart Device Programmability option is selected when Visual Studio is installed; without this, the SDKs will not be able to install the full range of C++ options. The next step is to download and install the required SDK, which will integrate with Visual C++ and add a number of new options to various Smart Device project templates.

There are a number of different project types available for mobile development; the three main options are Win32, MFC, and ATL. The options have the same pros and cons as their desktop equivalents—Win32 provides the leanest executable with the easiest deployment requirements but comes at the expense of a more tedious developer experience. ATL is a lightweight application framework optimized for COM development and allows both DLL and EXE development for CE-based devices, and MFC provides the richest framework for application development at the expense of a heavier runtime. MFC has separate projects for executables, ActiveX controls, and DLLs.

Visual C++ Smart Device Primer

Once the appropriate project type has been selected, the supported platforms for the project need to be selected, as shown in Figure 1. Each additional supported platform adds a separate build configuration to the project in much the same way as having different 32- and 64-bit build configurations for a desktop application. It is also possible to add new configurations to support different processor architectures and different compile options.

Figure 1: Supported Windows Mobile Platforms

With desktop development, pressing the F5 key launches the application and attaches the debugger, but for smart device applications, they need to be run in an environment that simulates the real-world device that they will run on. The Windows Mobile SDKs ship with a number of emulators that correspond to a variety of device form factors that exist, and these can be selected from a drop-down on the Visual Studio Devices toolbar, as shown in Figure 2.

Figure 2: Device Emulators Available with Windows Mobile 6

When F5 is pressed inside Visual Studio for a Smart Device project, the nominated emulator will launch, Visual Studio will deploy the application to the device, and it will be launched with the debugger attached. Figure 3 shows a 'Hello World' MFC application running on the Windows Mobile 6 Classic Emulator.

Figure 3: MFC Hello World on Windows Mobile 6 Classic Emulator


Hopefully, this article has lifted some of the mystery surrounding mobile-device development. Once the confusing array of terminologies has been peeled back, mobile development is not as complex as it initially appears, and Visual Studio offers tremendous support for development and debugging of mobile applications. With the basics out of the way, you'll dig deeper into the various subtleties of MFC, ATL, and Win32 Mobile Development in the next article.

About the Author

Nick Wienholt is a Windows and .NET consultant based in Sydney, Australia. He has worked on a variety of IT projects over the last decade and continues to stay involved in the developer community. Nick is the co-founder and president of the Sydney Deep .NET User group, writes technical articles for Pinnacle Publishing and the Microsoft Developer Network, and is a participant in many .NET-related newsgroups. Nick's most recent book is Maximizing .NET Performance.


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Businesses are moving more and more of their customer transactions to the web. Security is understandably a top concern as online transactions increase, so it is important to make sure your electronic signature provider meets the highest security standards. That means more than simply passing a security audit or obtaining a certification. This white paper provides recommendations for taking a broader view of e-signature security, and answers key questions that help identify the security requirements against …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds