dc4d+@andrew.cmu.edu (Darius Clynes) (08/20/89)
Under Finder the following works without any noticeable problems:
myLaunch(progname)
char *progname; /* the pascal string filename */
{
_exiting(1); /* recommended in LSC 3.0 patch4 */
Launch(0,progname); /* old style launch w/ def. scrn/snd buf */
ExitToShell(); /* for safety in case of return or error */
}
HOWEVER, under Multifinder (on a MacIIx with 5meg) strange things happen
The first launch seems to work, but subsequent launches crash. On an
SE with 2meg the first launch crashes also.
Having used the Bruce Ballard method of sublaunching with a LaunchStruct
(new method) I obtained the same problem result he did, using both
xC0000000 and x00000000 as LaunchFlags... no launch at all, just bell,
and bye. Ben Cranston's MPW version does not seem to apply easily
to Lightspeed 3.0 patch 4 ?? Help please!!!
-Darius Clynes dc4d@andrew.cmu.edu Tel (412) 268 3148 Carnegie Mellon Univ.
wetter@cup.portal.com (Pierce T Wetter) (08/22/89)
The following is a code fragment to launch an application from another application. This example will look through the DeskTop file for MPW, and Launch it. main() { DialogPtr welcome; SFReply result; SFTypeList ugh; PathHandle grabme; char fname[256]; Point where; HFileInfo pblock; WDPBRec wblock; LaunchStruct stuff; short err,vref,dref; long autotype; unsigned long desksize; Handle dhandle; DeskStruct *deskp; char *tmp; InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent,0); InitWindows(); InitMenus(); TEInit(); InitDialogs(0L); InitCursor(); autotype= 'MPS '; welcome=GetNewDialog(WELCOME_ID, nil, -1L); if (welcome) DrawDialog(welcome); fname[0]=0; GetVol(fname,&vref); fname[ ++fname[0]] = ':'; fname[ ++fname[0]] = 'D'; fname[ ++fname[0]] = 'e'; fname[ ++fname[0]] = 's'; fname[ ++fname[0]] = 'k'; fname[ ++fname[0]] = 't'; fname[ ++fname[0]] = 'o'; fname[ ++fname[0]] = 'p'; dref=OpenRFPerm(fname, 0, 1); err=ResError(); if (err) ERROR(err); dhandle= GetResource('APPL',0); /*Get list of applications from desktop*/ err=ResError(); if (err) ERROR(err); HLock(dhandle); deskp = (DeskStruct *) *dhandle; desksize= SizeResource(dhandle); while ((unsigned long) deskp < (unsigned long) *dhandle + (unsigned long) desksize) { if (deskp->crType == autotype) break; tmp= (char *) deskp; tmp += sizeof(long) + sizeof(long) + deskp->name[0]+2; if (deskp->name[0] & 1) tmp -= 1; deskp = (DeskStruct *) tmp; } if (deskp->crType != autotype) goto lastresort; autotype = deskp->dirID; BlockMove(&deskp->name[0],&fname[0],32); HUnlock(dhandle); CloseResFile(dref); wblock.ioNamePtr=0L; pblock.ioNamePtr= (unsigned char *) &fname[0]; wblock.ioVRefNum=vref; pblock.ioVRefNum=vref; pblock.ioFDirIndex=0; pblock.ioDirID = autotype; wblock.ioWDProcID = 'ERIK'; wblock.ioWDDirID = autotype; err=PBOpenWD(&wblock,false); if (!err) { err=PBGetCatInfo( &pblock,false); if (!err) { err=SetVol(nil, wblock.ioVRefNum); if (err) ERROR(err); InstallPatch(fname); stuff.pfName = fname; stuff.param = 0; stuff.LC[0]='L'; stuff.LC[1]='C'; stuff.extBlockLen=6; stuff.fFlags = pblock.ioFlFndrInfo.fdFlags; stuff.launchFlags=0; err=LaunchIt( &stuff); } } lastresort: ugh[0]='APPL'; where.h=200; where.v=200; SFGetFile(where,"",nil,1,ugh,nil,&result); if (result.good) { /*wblock.ioVRefNum=result.vRefNum; wblock.ioWDIndex=0; wblock.ioWDProcID=0; wblock.ioWDVRefNum=vref; wblock.ioNamePtr=(unsigned char *) fname; err=PBGetWDInfo(&wblock,FALSE);*/ pblock.ioNamePtr= (unsigned char *) &result.fName; pblock.ioVRefNum=result.vRefNum; pblock.ioFDirIndex=0; pblock.ioDirID = 0; err=PBGetCatInfo( &pblock,false); if (err) ERROR(err); err=SetVol(nil, result.vRefNum); if (err) ERROR(err); InstallPatch(); stuff.pfName = (char *) &result.fName; stuff.param = 0; stuff.LC[0]='L'; stuff.LC[1]='C'; stuff.extBlockLen=6; stuff.fFlags = pblock.ioFlFndrInfo.fdFlags; stuff.launchFlags=0; /*0xC000000 for sub-launch err=LaunchIt( &stuff); if (err) ERROR(err); } } /* Header file*/ #define nil 0L #define ERROR(err) ExitToShell(); typedef struct _LaunchStruct { char *pfName; short param; char LC[2]; long extBlockLen; short fFlags; long launchFlags; } *pLaunchStruct, LaunchStruct; typedef struct _DeskStruct{ long crType; long dirID; char name[1]; } DeskStruct; This code is provided with no garuntees whatsoever. Pierce