free web page counters

Windows Mobile Pocket PC Smartphone Programming

==>Click here for the SiteMap<==. Original contents with decent amount of source codes.

Wednesday, May 03, 2006

Pocket PC Console for standard input and standard output: A convenient tool for lazy debugging and tracing in Pocket PC 2003 devices

====>SiteMap of this Blog<===

Pocket PC Console for standard input and standard output: A convenient tool for lazy debugging and tracing in Pocket PC 2003 devices

Debugging and tracing sometimes can be a tricky business, especially for a multi-threaded program.

  • Log file is used most commonly.
  • OutputDebugString is also nice, and there is no need to write any code to deal with a log file. However, you do need to attach the debugger to receive the debugging message.

Probably the simplest approach, requiring neither a log file nor a debugger, is the famous printf (or the C# equivalent Console.Write, or the Java equivalent System.out.println). The simplicity of using printf, and the beautify of showing messages on a console in real time, make printf a very nice tool for lazy programmers :)

Pocket PC Shell

Unfortunately there is no built-in console (therefore no standard input and standard output) in Windows Mobile devices. Even if your code compiles and builds correctly, there is no way you can see the messages.

One tool coming for rescue is PPC Command Shell, part of Microsoft Windows Mobile Developer Power Toys. See my article "How to launch a program via command line in Pocket PC 2003 device and Pocket PC 5.0 device?" for a brief introduction on those nice little tools.

  • PPC Command Shell - Command shell for the Pocket PC 2003 device.

Once installed, three files can be found in the desktop PC's destination folder:

  • console.dll: copying it to the device's \Windows folder
  • shell.exe: copying it to any folder in the device
  • cmd.exe: copying it to any folder in the device

The only files needed for printf to work are console.dll and shell.exe. These two provide the console, supporting standard input and standard output. Once invoked, shell.exe stays in the memory. In fact, upon running, shell.exe put an entry under registry HKLM\Init, so as to make sure itself is always up and running (even before the OS kernel components, like device.exe, gwes.exe, and etc.)


The executable cmd.exe is not needed. It solely provide implementations of some commonly used DOS prompt commands, for example, dir, cd.

Below is a simple testing program:

printf("This is a test");
MessageBox(NULL, TEXT("Console Test!"), TEXT("Demo"),

And here is the screen cut when the program runs:

Warning: This tool does not work in Pocket PC 5.0 device, nor does it work in any Smartphone device. In fact, the following warning is popped up if running in Smartphone 2003 device:

Wrap Up

Pocket PC Shell is a simple yet powerful tool for debugging or tracing in real time. However, the one packaged in Microsoft's Mobile Power Toy can only work in Pocket PC 2003 device (inclduing 2003 SE).

There is another free tool but I've never tested it. Looks like it has not been updated for quite a while.

Notice: Never compile printf into your release build! The printf and console processing code are not simple thus sort of eating the CPU!

====>SiteMap of this Blog<===