5. A Hello World Program

Now you can compile a hello proggie.

I had to hack up all the demos from the HOWTOs after reading the SDK header files. The header names, primitive types, and compiler tool's names are incorrect for version 3.5 of the PalmOS SDK in the HOWTO samples. Plus, it appears that the Examples that come with the SDK all have zero length resource files (e.g. SampleCalculator.rsrc). I compiled the packages, but they crashed on the emulator.

Save the below snippet in a text file called hello.c .

hello.c



#include <PalmOS.h>

// ---------------------------------------------------------------------
// PilotMain is called by the startup code and implements a simple event
// handling loop.
// ---------------------------------------------------------------------
UInt32 PilotMain( UInt16 cmd, void *cmdPBP, UInt16 launchFlags )
{
    EventType event;


    if (cmd == sysAppLaunchCmdNormalLaunch) {

        //  Display a string.
        WinDrawChars( "Hello, world!", 13, 55, 60 );

        //  Main event loop:
        do {
            //  Doze until an event arrives.
            EvtGetEvent( &event, evtWaitForever );

            //  System gets first chance to handle the event.
            SysHandleEvent( &event );

            //  Normally, we would do other event processing here.

        // Return from PilotMain when an appStopEvent is received.
        } while (event.eType != appStopEvent);
    }
    return;
}


You can compile it like this. Did you fix your PATH to have /usr/local/palm/bin ?


      m68k-palmos-gcc hello.c -o hello
      m68k-palmos-obj-res hello
      build-prc hello.prc "Hello, World" WRLD *.hello.grc

Blamho! Now you'll have a hello.prc that you can put in the emulator (works!) or in your palm (WORKS!).