Path: utzoo!attcan!uunet!portal!cup.portal.com!wetter From: wetter@cup.portal.com (Pierce T Wetter) Newsgroups: comp.sys.mac.programmer Subject: Re: Launching problem in Lightspeed C 3.0 Message-ID: <21506@cup.portal.com> Date: 22 Aug 89 00:59:09 GMT References: Organization: The Portal System (TM) Lines: 176 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