Is it legal to call the MemHandleToLocalID() function on a chunk in the
dynamic heap (as opposed to data storage)? I have an application that does
this, but it now gets a warning in the emulator when running the PalmOS 3.3
debug ROMs: "MemHandleToLocalID: handle not in storage heap". I do not get
this warning when running the PalmOS 3.0 ROM.

What's even more interesting is that when I call MemLocalIDToGlobal() on
the returned local ID, I don't get the original handle back using the 
Palm III 3.3 ROM. However, the Palm IIIx-V 3.3. ROM does return the original
handle.

I included the source code for a small test case below. When I run this
program on OS 3.0 or the Palm V 3.3, I see something like the following:

Memory handle = 0x800014A8
Local ID = 0xF00014A9
Local ID handle = 0x800014A8

However, when I run it on Palm III 3.3, I get:

Memory handle = 0x800015DC
Local ID = 0x000015DD
Local ID handle = 0x900015DC

If I try to use the handle returned from MemLocalIDToGlobal (0x900015DC),
it blows up with an "Invalid handle" error. Am I doing something stupid or
unsafe here or is this an OS bug?

-------------------------------------------------------------------------
#include <Pilot.h>   
#include <SysEvtMgr.h> 
#ifdef __GNUC__
    #include "callback.h"
#endif

void MemHandleTest()
{
    FormPtr form;
    VoidHand newHandle, origHandle;
    LocalID localID;
    Char string[100];

    form = FrmNewForm(1000, "MemHandle test", 0, 0, 160, 160, false, 0, 0, 0);
    ErrFatalDisplayIf(form == NULL, "Could not create form");
    FrmDrawForm(form);

    origHandle = MemHandleNew(sizeof(Long));
    ErrFatalDisplayIf(origHandle == NULL, "Could not alloc handle");
    StrPrintF(string, "Memory handle = 0x%lx", origHandle);
    WinDrawChars(string, StrLen(string), 0, 20);

    localID = MemHandleToLocalID(origHandle);
    StrPrintF(string, "Local ID = 0x%lx", localID);
    WinDrawChars(string, StrLen(string), 0, 40);

    newHandle = MemLocalIDToGlobal(localID, 0);
    StrPrintF(string, "Local ID handle = 0x%lx", newHandle);
    WinDrawChars(string, StrLen(string), 0, 60);

    MemHandleFree(origHandle);
}
    

DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) 
{
    EventType event;
#ifdef __GNUC__
    CALLBACK_PROLOGUE
#endif

    switch (cmd) {
        case sysAppLaunchCmdNormalLaunch:
            MemHandleTest();

            do {
                EvtGetEvent(&event, evtWaitForever);
                if (! SysHandleEvent(&event))
                   FrmDispatchEvent(&event);
            }   
            while (event.eType != appStopEvent);

            FrmCloseAllForms();
            break;
    }

#ifdef __GNUC__
    CALLBACK_EPILOGUE
#endif
    return 0;
}
-----------------------------------------------------------------------------

Thanks,
John Ludwig
[EMAIL PROTECTED]

Reply via email to