4,453,617 members and growing!   20,561 now online.
Email Password Password problem?
All Topics, MFC/C++ >> PDA / Embedded >> General  (Beginner)

An introduction to the Palm platform
By Christian Graus.

An overview of the Palm world, including a list of C functions which have preferred equivalents in PalmOS
C++, C
WinCE, PalmOS, Windows
PDA, Win32, VS
Dev
Posted: 8 Nov 2002
Views: 74,230
Announcements


Search    
Advanced Search
Sitemap
PrintBroken Article?Bookmark Discuss Send to a friend
Rating error: You must be signed in to vote
17 votes for this article.
Popularity: 5.73. Rating: 4.66 out of 5.

Introduction

Welcome to this, the first in a series of articles on Palm development. So why Palm ? In my case, the decision was customer driven, however the reason for the customers decision was that the Palm platform is widely accepted, inexpensive and easy-to-use. Although I was initially cynical, I have to say that I have come to love the platform also. For me as a developer the reasons are somewhat different. The Palm platform gives me the opportunity to write code for a platform where speed is not so easy to come by, where resources are limited, and where code needs to be tightly written in order to be usable at all. I hope that excites more people than it scares away, it's certainly not all bad news. While the platform is certainly not as powerful as your desktop PC, you still are able to develop code on your desktop, using modern tools and compilers. The purpose of this first article is simply to provide an overview of Palm development, and discuss some of the options that you will have if you decide to develop for it.

I can't afford a Palm

It doesn't matter if you don't have a Palm handheld unit, because the people at Palm kindly provide a Palm emulator which runs on your desktop, is integrated with common IDE's, and even provides debugging support. The bad news is it does not come with any ROM's, which basically means it's useless. Palm provide a developer program through which you can gain access to ROM's, but if you are outside the US this involves filling in a form, which I sent off months ago and got no reply. The emulator does come with a utility for downloading a ROM to your desktop, which is what I eventually did. The link for the emulator is with the rest of the links, at the end of the article.

Languages

It is possible to code for palm in many languages, including Java, basic, C++, or using a number of R.A.D. environments. However, as I have already said, the palm platform is not highly powered, and for that reason I choose to develop for it in straight C. There are a number of C++ class libraries which seek to provide a MFC style wrapper around the C API. I chose to reject this approach even when it claimed to be lightweight because to do so would cut me off from the mainstream in terms of literature and support, and tie me to a product whose lifespan I could not predict.

Compilers

There are a number of compilers available for palm development for Windows. The two most common compilers are probably CodeWarrior and GCC. There are a number of other compilers available, most of which use GCC to do the actual compiling. Of those I personally chose to purchase developer studio from Falch.net. My reasons were that the IDE is very similar to Visual C++ 6 which made it easy to learn to use, and I found it much more intuitive than CodeWarrior. However, that does not mean that my choice should be your choice, and I recommend you investigate the various compilers available. CodeWarrior has the advantage of being the industry standard for palm, GCC has the advantage of being free. So long as you choose a compiler which will build palm programs written in C, you will be able to follow my tutorials. Certainly, if you're looking for a free option, the demo of the Falch compiler should do you for much of the tutorials.

C API

I guess if there's one point I intend to labour, it's that developing for palm means writing optimized code. This is so much the case, that the palm API provides alternatives to functions from the sea runtime library, in order to avoid code bloat caused by linking to that library. The following table lists a number of C functions and their palm equivalents. Print this out and put it somewhere prominent. You will refer to it often.

C Function Palm API Equivalent
strlen StrLen
strcpy StrCopy
strncpy StrNCopy
strcat StrNCat
strcmp StrCompare
strncmp StrNCompare
itoa StrIToA
strchr StrChr
itoa StrIToA
strchr StrChr
sprintf StrPrintF
svprintf StrVPrintF
malloc MemPtrNew
free MemPtrFree
memmove MemMove
memset MemSet
memcmp MemCmp

You will notice that unlike the standard library, the Palm functions feature a lot of capitalisation, and that the string functions all begin with Str, and the memory functions all begin with Mem. This is a common theme in Palm development, and you will find that each library in the Palm OS has its own prefix for all functions found in it.

Your developer ID

Another quirky thing about Palm development is a simple fact that your hard drive is your RAM. This is actually an area where performance can be good, because to search through your record set does not require any mechanical process, simply locking of areas of memory and direct access. This does however mean that in theory your application has access to all of the programs and data on your unit. The reason this is not the case is a mechanism whereby you need to know some information about a database before you can gain access to it records. Part of this mechanism involves the assignment of a unique, 4 letter ID. The process is simple, it just involves entering your proposed ID on the Palm site, where you will be advised if the ID has been assigned to you or was previously assigned. The ID must be in capital letters, as all lowercase letters are reserved for use by Palm.

int main()

As you may be aware, the Windows API expects a function called WinMain, rather than main as its initial entry point. The Palm API continues the tradition, its entry point is known as PilotMain. The reason for this is that the original Palm product was called the PalmPilot. Believe it or not, I finally going to show you some code.

Hello Palm Pilot

UInt32 PilotMain (UInt16 launchCode, MemPtr launchParameters, 
                                        UInt16 launchFlags) 
{ 
    EventType event; 
    if (launchCode == sysAppLaunchCmdNormalLaunch) 
    { 
        WinDrawChars( "Hello, world!", 13, 55, 60 ); 
        do 
        { 
            EvtGetEvent( &event, evtWaitForever ); 
            SysHandleEvent( &event ); 
        } while (event.eType != appStopEvent); 
    } 
    return; 
}

As we delve deeper into the Palm API in the coming articles, you will come to realize how much of a barebones example this is, nevertheless it is customary to begin teaching with such example, and who am I to break tradition ? Even so, there is much to be learned from this example. For starters, the Palm system is event driven. I'm sure this hardly comes as a surprise. What may be more surprising, is that the Palm defines its own types. The reason for this is simple: the Palm can be developed for on any system that offers a C compiler. That being the case, it is better that the Palm API provide guarantees regarding the size of numeric variables in particular, but also the nature of variables in general. The Palm API often appends the word 'type' to its types, as in the EventType in this example. The event type is simply an event, which the API catches and in a full example passes to the menus and our own event loop as well as to the system. In this case we merely check the launch code to see if the application is being launched normally, draw our string and run a minimal event loop so that our program will respond when the buttons are pressed to move to a different program or back to the main screen. The next article will introduce forms development, that is to say building a GUI and an event loop to allow user interaction.  I know it's a lot of work to get to the point where you have everything you need and can build Palm apps, I promise you that it's worth it.  I've had a lot of fun getting to the point that I can write these articles, I hope you have as much fun joining me.

Links:

  • www.palmos.com - This is where to go for the Palm SDKs and to sign up for the developer program to get the ROMs for the emulator. The emulator and other tools are also available here, but you may get them with your compiler
  • Code Warrior - The standard for Palm development, but in my opinion a little pricey and hard to use
  • www.falch.net - In my opinion an excellent product, comes with the emulator, etc. and the demo is not time limited ( although it is limited in other ways )
  • news://news.falch.net - The people who made my favorite compiler also host a news feed full of information about Palm.

About Christian Graus


Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and asp.net in my job at Dytech. After 4 years there, I've started working from home, for Code Project and on an image processing program for the Vet market.

Click here to view Christian Graus's online profile.


Other popular PDA / Embedded articles:

[Top] Sign in to vote for this article:     PoorExcellent  
Note: You must Sign in to post to this message board.
FAQ Message score threshold    Search comments  
 View   Per page  
 Msgs 1 to 21 of 21 (Total: 21) (Refresh)First Prev Next     
Subject 
Author 
Date 
  flach.net???
 freddy1ca 4:34 4 Aug '04 
  Re: flach.net???
 Christian Graus 16:59 4 Aug '04 
  Please update the pilot.programmer.* news server!
Unconfirmed/Anonymous posting Guilherme Hazan 20:53 30 Nov '03 
  Re: Please update the pilot.programmer.* news server!
 Christian Graus 21:35 30 Nov '03 
  Christian hope you don't find this question to OT...
 Code4Food 12:41 4 Dec '02 
  Re: Christian hope you don't find this question to OT...
 Christian Graus 14:46 4 Dec '02 
  Fach.net now Moribund (04-2004)
 k6whp 17:36 30 Apr '04 
  expect the next one of this series
 ruihuahan 20:02 12 Nov '02 
  Re: expect the next one of this series
 Christian Graus 20:34 12 Nov '02 
  Great idea
 Massimo Colurcio 14:03 9 Nov '02 
  Re: Great idea
 Christian Graus 16:39 9 Nov '02 
  WinCE
 Mario M. 11:11 9 Nov '02 
  Re: WinCE
 Christian Graus 16:38 9 Nov '02 
  Nice for PalmOS starters
 Nishant S 20:02 8 Nov '02 
  Re: Nice for PalmOS starters
 Christian Graus 21:07 8 Nov '02 
  Registering for access to Palm ROMs
 Gavin Greig 6:30 8 Nov '02 
  Re: Registering for access to Palm ROMs
 Christian Graus 15:16 8 Nov '02 
  Re: Registering for access to Palm ROMs
Unconfirmed/Anonymous posting Garth Lancaster (In Global Roam Mode) 16:10 8 Nov '02 
  Re: Registering for access to Palm ROMs
 Christian Graus 16:15 8 Nov '02 
  Re: Registering for access to Palm ROMs
 Gavin Greig 3:54 11 Nov '02 
  Re: Registering for access to Palm ROMs
 Christian Graus 4:17 11 Nov '02 
Last Visit: 6:11 Friday 31st August, 2007First Prev Next     

General comment    News / Info    Question    Answer    Joke / Game    Admin message


Updated: 8 Nov 2002 Article content copyright Christian Graus, 2002
everything else Copyright © CodeProject, 1999-2007.
Web17 | Advertise on The Code Project | Privacy

The Ultimate ToolboxASP AllianceDeveloper FusionDevelopersdexDevGuruProgrammers HeavenPlanet Source CodeTek-Tips Forums
Help!
Articles
Message Boards
Lounge
What is 'The Code Project'?
General FAQ
Post a Question
Site Directory
About Us
Latest
Most Popular
Search
Site Directory
Submit an Article
Update an Article
Article Competition
Windows Vista
Visual C++
ATL / WTL / STL
COM
C++/CLI
C#
ASP.NET
VB.NET
Web Development
.NET Framework
Mobile Development
SQL / ADO / ADO.NET
XML / XSL
OS / SysAdmin
Work Issues
Article Requests
Collaboration
General Discussions
Hardware
Algorithms / Math
Design and Architecture
Subtle Bugs
Suggestions
The Soapbox