Portability Issues
There are two important portability issues that you need to take into account when moving data back and forth from the handheld to the desktop. They are byte ordering and structure packing.
Byte Ordering
The Palm OS runs on a Motorola platform, which stores bytes differently from Windows running on an Intel platform. This crucial difference can royally mess up data transfers if you are not careful.
On the handheld, the 16-bit number 0x0102 is stored with the high byte, 0x01, first, and the low byte, 0x02, second. In the conduit on Windows, the same number is stored with the low byte, 0x02, first, and the high byte, 0x01, second. As a result, any two-byte values stored in your records or in your AppInfo block must be swapped when transferred between the two systems. (If you fail to swap, a simple request for 3 boxes of toys on the handheld would be processed on the desktop as a request for 768 boxes!) A similar problem occurs with four-byte values; they are also stored in switched forms (see Table 12.2).
Table 12-2. Comparison of Byte Orderings for the Four-Byte Value 0x01020304
Palm Handheld Byte Order |
Wintel Byte Order |
---|---|
0x01 |
0x04 |
0x02 |
0x03 |
0x03 |
0x02 |
0x04 |
0x01 |
Note
Strings are not affected by this byte ordering. On both platforms, the string “abc” is stored in the order “a”, “b”, “c”, “\0”.
The HotSync Manager provides routines for converting two- and four-byte values from the handheld to host byte ordering:
Word SyncHHtoHostWord(Word value) DWord SyncHHToHostDWord(DWord ...
Get Palm Programming: The Developer's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.