StrPrintF is a derivative of the classic printf – Palm OS programmers who never programmed console applications(like me, I come from the VB side of the river) have little experience with this call. For them, this bit of code looks perfectly ok:
//Prefs.highscores[i].secs is a UInt32
StrPrintF(textparams.text,"%2d:%2d %s %s",
However, when the app containing this code is run on the Palm OS Simulator, a very strange thing happens. The Palm OS Simulator crashes…on OS level. Windows gives a message about how the Simulator attempted to access memory around 0×000000043 or so(very low memory area) – cool. A Palm OS app that crashes Windows 2000 =).
The problem is the type of the secs field. When you specify a %d, StrPrintF expects a regular int, not a Int32. So, it reads only half of the data into memory, leaving the other half on the stack. When the two %d’s have been processed(one UInt32 taken off the stack, one to go), the %s’ses fetch their pointers off the stack, thereby getting the second UInt32. This then leads to a beautiful crash as experienced above…
This could be handy to keep in mind for another time I use StrPrintF….maybe it can help you all, too!