Hi,

I was wondering if any one could help me see what's going wrong with the
following code.  I've developed two application under CodeWarrior 6 called
Starter (based on the Stationery) which extracts a string from it's resource
file and displays it in an uneditable text field.  And Test which one
execution is supposed to call the Starter app but this time display a string
from Test resources.

When I run Test once it executes perfectly and displays the correct string.
But when I try to run it a second time I get the following error from the
Emulator:

"MemoryMgrNew.c, Line:4128, Invalid handle".
"MemoryMgrNew.c, Line:4160, Nil Ptr"

I was really hoping that someone would be able to take a look at the code
I've quoted below and help me out.  As this functionality is the basis for a
major application I am writing.

Thanking you,

Sally-Anne
___________________________________________________________
Test uses the following function StartOtherApp to call the other
application.
Which extracts the resource string and then calls SysUIAppLaunch.

Err  StartOtherApp(void)
{

LocalID   dbId, Id
CharPtr   cmdPBP;
CharPtr  src = "";
Err    error;
UInt    cardNo;
VoidHand   Resource;

error = SysCurAppDatabase(&cardNo, &Id);


Resource = DmGet1Resource('tSTR', ScriptString);
cmdPBP = MemHandleLock(Resource);
MemHandleUnlock(Resource);
DmReleaseResource(Resource);


dbId = DmFindDatabase(0, "Starter");
error = MemPtrSetOwner(cmdPBP,0);
if (error)
 return error;

error = SysUIAppSwitch(0,dbId, sysTclLaunch ,(Ptr) cmdPBP);
}

Starter there has, in StarterPilotMain, The following switch which
distinguished between the two start up launch codes. (sysTclLaunch = 32768).

switch (cmd)
  {
  case sysAppLaunchCmdNormalLaunch:
   input = NULL;
   error = AppStart();
   if (error)
    return error;

   FrmGotoForm(MainForm);

   AppEventLoop();
   AppStop();
   break;

  case sysTclLaunch:
   input = MemPtrNew(StrLen((CharPtr) cmdPBP)+1);
   StrCopy(input,(CharPtr) cmdPBP);

   if (error)
    return error;
   error = AppStart();
   if (error)
    return error;


   FrmGotoForm(MainForm);

   AppEventLoop();
   AppStop();
   break;
  }

When Starter finally gets a frmOpenEvent it does the following the display
the appropriate resource string:

case frmOpenEvent:
   frmP = FrmGetActiveForm();
   if (input == NULL) /* Launched Normally - extract Starter's string*/
   {
    error = SysCurAppDatabase(&cardNo, &Id);
    if (error)
     return error;

    dbref = DmOpenDatabase(cardNo,Id, dmModeReadOnly);
    resourceIndex = DmFindResource(dbref,'tSTR', ScriptString, NULL);
    Resource = DmGetResourceIndex(dbref,resourceIndex);
    strP = MemHandleLock(Resource);
   }
   else
   {
    strP = input;
   }
   MainFormInit( frmP);
   fld = FrmGetObjectId(frmP,FrmGetObjectIndex(frmP, MainEditFieldField));
   SetFieldTextFromStr(fld,strP);
   FrmDrawForm(frmP);
   if (input == NULL)
   {
    error = MemHandleUnlock(Resource);
    error = DmReleaseResource(Resource);
    DmCloseDatabase(dbref);
   }
   else
   {
    MemPtrFree(input);
   }

   break;

Which used the following function:


static void SetFieldTextFromStr(Word fieldID, CharPtr strP)
{
 FormPtr frm = FrmGetActiveForm();
 FieldPtr fldP;

 fldP = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,fieldID));

 ErrNonFatalDisplayIf(!fldP, "missing field");

 FldSetTextPtr(fldP, strP);
 FldRecalculateField(fldP, true);
 FldDrawField(fldP);
}





Reply via email to