Alan.Michelson@f141.n102.z1.FIDONET.ORG (Alan Michelson) (03/19/90)
Technical Note #126 page of 5 Sublaunching1 Macintosh Technical Notes #126: Sublaunching: Playing the Shell Game See also: The Segment Loader Written by: Rick Blair May 4, 1987 Updated: March 1, 1988 Revised by: Darin Adler August 1, 1988 Note: Macintosh Technical Support takes the view that this is a feature which is best left out for compatibility (and other) reasons, but we want to make sure that when it is absolutely necessary to implement it, it is done in the safest way. Herein is a means to launch an application from your program and have it return to you as though you were a"shell, like the Finder. There are unresolved issues, though (and some downright problems), so please read the cautionary notes which follow. Changes since 5/87 include advising you to set both high bits of LaunchFlags for future compatibility. Throwing away working directories that you created is no longer recommended. If you are opening working directories, you should make sure to check for errors (tMWDOErr ="121) after calling PBOpenWD. ___________________________________________________________________________ ___________________ Warning: The interface to the Launch trap will change in the not-too-distant future. When that happens, programs which launch other applications will break. You should really only consider doing this if you are implementing an integrated development system. The Finder does a lot of hidden cleanups and other tasks of which the user isnt aware. Therefore it is best if you dont try to replace the Finder with a"mini, or try to launch other programs and have them return to your application. In the future the Finder may provide better integration for applications and you would circumvent this if you tried to take over its role. MultiFinder treats sublaunching differently. Refer to Technical Notes #180 and #205 for discussion of the Launch trap under MultiFinder. Nevertheless, consider a text editor that wants to allow the user to run, say, ResEdit, and then return to program editing. If it isnt worried about the transition to new environments, then it would want to do this in a way that would fit into the current system well. System file version 4.1 (or higher) includes a mechanism for allowing a call to another application which we term a sublaunch. This is accomplished with a set of simple extensions to the parameter block which is passed to the Launch trap. Note that for future compatibility we assume that Launch will return. A Sublaunch from Pascal {It is assumed that the Signals are caught elsewhere; see Technical Note #88 for more information on the Signal mechanism} {the extended parameter block to _Launch} TYPE pLaunchStruct = ^LaunchStruct; LaunchStruct = RECORD pfName : StringPtr; param : INTEGER; LC : PACKED ARRAY[0..1] OF CHAR; {extended parameters:} extBlockLen : LONGINT; {number of bytes in extension = 6} fFlags : INTEGER; {Finder file info flags (see below)} launchFlags : LONGINT; {bit 31,30=1 for sublaunch, others reserved} END; {LaunchStruct} FUNCTION LaunchIt(pLaunch: pLaunchStruct): OSErr; {< 0 means error} INLINE $205F, $A9F2, $3E80; { pops pointer into A0, calls Launch, pops D0 error code into result: MOVE.L (A7)+,A0 _Launch MOVE.W D0,(A7) ; since it MAY return } PROCEDURE DoLaunch; VAR myLaunch : LaunchStruct; {launch structure} wher : Point; {where to display dialog} reply : SFReply; {reply record} myFileTypes : SFTypeList; {we only want APPLs} numFileTypes : INTEGER; myPB : CInfoPBRec; dirNameStr : str255; BEGIN wher.h := 20; wher.v := 20; numFileTypes:= 1; myFileTypes[0]:= 'APPL'; {applications only!} {Let the user choose the file to Launch} SFGetFile(wher, '', NIL, numFileTypes, myFileTypes, NIL, reply); IF reply.good THEN BEGIN dirNameStr:= reply.fName; {initialize to file selected} {Get the Finder flags} WITH myPB DO BEGIN ioNamePtr:= @dirNameStr; ioVRefNum:= reply.vRefNum; ioFDirIndex:= 0; ioDirID:= 0; END; {WITH} Signal(PBGetCatInfo(@MyPB,FALSE)); {Set the current volume to where the target application is} Signal(SetVol(NIL, reply.vRefNum)); {Set up the launch parameters} WITH myLaunch DO BEGIN pfName := @reply.fName; {pointer to our fileName} param := 0; {we dont want alternate screen or sound buffers} LC := 'LC'; {here to tell Launch that there is non-junk next} extBlockLen := 6; {length of param. block past this long word} {copy flags; set bit 6 of low byte to 1 for RO access:} fFlags := myPB.ioFlFndrInfo.fdFlags; {from GetCatInfo} LaunchFlags := $C0000000; {set BOTH high bits for a sublaunch} END; {WITH} {launch; you might want to put up a dialog which explains that the selected application couldnt be launched for some reason.} Signal(Launchit(@myLaunch)); END; {IF reply.good} END; {DoLaunch} -- Alan Michelson via cmhGate - Net 226 fido<=>uucp gateway Col, OH UUCP: ...!osu-cis!n8emr!cmhgate!102!141!Alan.Michelson INET: Alan.Michelson@f141.n102.z1.FIDONET.ORG