free web page counters

Windows Mobile Pocket PC Smartphone Programming

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

Thursday, November 17, 2005

How to debug Control Panel Applet in Pocket PC 2003 and Pocket PC 5.0?

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

How to debug Control Panel Applet in Pocket PC 2003 and Pocket PC 5.0?

Recently I was enhancing a Control Panel Applet for my Pocket PC application, which was developed in a hurry one year ago, with very rudimentary user interfaces. This time I expanded it to 4 tabs, with more professional UIs.

All went on well, until I hit a problem today: After making some code changes, the Applet no longer shows up after I click it! Not able to find out any issue from the source code, I decided to do a debug. Unfortunately a Control Panel Applet cannot be directly started, because it is essentially a DLL which exports a CPlApplet function. So I have to find a host executable for debugging purpose.

1. Basic knowledge about Pocket PC Control Panel Applet

The way how Control Panel Applet is loaded by the system is well documented. Basically the CPL file must export the following function:

LONG CALLBACK CPlApplet (HWND hwndCPL, UINT uMsg, LONG lParam1, LONG lParam2)

And the CPL must be able to deal with a series of messages sent from Windows, namely:

CPL_GETCOUNT
CPL_INIT
CPL_NEWINQUIRE
CPL_STOP


2. Write my own host executable? Overkill?

So I can easily write a program that

  • load the CPL ("LoadLibrary")
  • get the function address of CPlApplet("GetProcAddress"),
  • and send a series of messages: CPL_INIT, CPL_GETCOUNT, CPL_NEWINQUIRE, CPL_DBLCLK (to show the UI!), CPL_STOP, and CPL_EXIT

I actually find such one, although it does not send CPL_DBLCLK to display the UI.

3. ctlpnl.exe? Nope it does not work!

It looks to me a little overkill to write a program just for the sake of a debugging. So I am wondering whether any program already resides in the device is a good host. A good candidate should be ctlpnl.exe as documented in MSDN example.

I was soon disappointed. Nope!! ctlpnl.exe does not work! Although I killed ctlpnl.exe using the remote process viewer, the VS2005 debugger still quickly terminates the debug session, because ctlpnl.exe unloads my CPL as soon as it loads it, then itself immediately dies.

4. mstli.exe ==> the good guy

After some digging, I found mstli.exe is the good one. It perfectly loads my CPL, waits for my click on the device, then stops at my breakpoint. I tested in my Sprint Smartdevice PPC6601 (Windows Mobile 2003SE), Sprint Smartdevice PPC6700 (Windows Mobile 5.0), Pocket PC 2003 emulator, Pocket PC 5.0 emulator, all work well.

One caveat: Looks like mstli.exe is started once the device is up and running. So it must be killed before the debugger can start it. I use the remote process viewer to kill it.



Category: [Control Panel]

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