Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!genrad!decvax!dartvax!earleh From: earleh@dartvax.UUCP Newsgroups: comp.sys.mac Subject: Re: Let's do _Launch Message-ID: <5686@dartvax.UUCP> Date: Sat, 14-Feb-87 13:55:31 EST Article-I.D.: dartvax.5686 Posted: Sat Feb 14 13:55:31 1987 Date-Received: Sun, 15-Feb-87 09:05:05 EST References: <1033@gould9.UUCP> Organization: Society for the Prevention of Cruelty to Graduate Students Lines: 127 Summary: I do it this way. In article <1033@gould9.UUCP>, joel@gould9.UUCP (Joel West) writes: > Has anyone out there gotten this to work? > > So far, I've figured out: > 1. It doesn't return an error, it crashes if it fails. > 2. You have to validate that the application exists. > I guess you'd also use GetFInfo to make sure it's APPL. > But what I'm not sure of is: > 3. Do I have to set the WD to be the WD of the application? > Launch has a name parm but no vol/wd parm. > 4. What would it do with a complete path name? > > Any advice would be appreciated. My 6-line launcher is a page > and growing. > -- > Joel West MCI Mail: 282-8879 > Western Software Technology, POB 2733, Vista, CA 92083 > {cbosgd, ihnp4, pyramid, sdcsvax, ucla-cs} !gould9!joel > joel%gould9.uucp@NOSC.ARPA Joel, This is a chunk of assembly code to illustrate using _Launch. Since you say "_Launch" instead of "Launch" or "Launch()" I assume you are using assembler instead of Pascal or C or Fortran or whatever. Instead of answering your questions directly, I say: Study the code, see how it works, determine whether you can improve on it. Some things to note: I wrote this as an application. If you want to use it in a larger program, then cut out all the Mac initialization crap and put an RTS at the end of it, right next to the "chicken:" label. The routine uses either a stack frame or constant data as storage, so it doesn't trample on any existing storage that may be used by your application. A more sophisticated use of "_Launch" is to pass the application a document to work with, much as done by MDS Edit when the Transfer menu says "Asm mds:src:xfer.asm". When you figure out how to do this, then your 6-liner gets really big! include mds:library:Pushpop.txt ;push and pop macros include mds:library:Packages.txt ;Macintosh package macros include mds:library:NewLib.D ;assembler equates from ;December, 1985 software ;supplement myparamblk equ -80 otherparamblk equ -160 SFReply equ -240 xdef Xfer Xfer: ; DC.W $4AFC ;For debugging only!! ; Initialize everything in case this is the startup application. ; ; Cut out all this stuff if you want to make a procedure/function/ ; subroutine out of it. ; quickGlobals EQU -4 endQuickGlobals EQU -grafSize;QuickDraw globals pea quickGlobals(a5);QuickDraw scratch area _InitGraf ;Init QuickDraw _InitFonts ;Init font package _InitWindows ;init windows package _InitMenus ;init menu package pea Xfer ;restart procedure _Initdialogs ;init dialog package _TEinit ;init text edit package push.l #$0000FFFF ;mask for all events _FlushEvents ;get rid of all events _InitCursor ;init the cursor ; ; End of stuff to cut out for procedure/subroutine/function. You ; may want to save caller's registers at this point. ; link a6,#-240 ;get a stack frame push.l SFPoint ;box coordinates clr.l -(sp) ;no prompt string clr.l -(sp) ;no file filter either push.w #$01 ;one type pea mytypelist ;push typelist pointer clr.l -(sp) ;no dialog hook procedure pea SFReply(a6) ;reply area pointer _SFGetFile ;call the package routine tst.w SFReply+rGood(a6) ;cancel button? beq endofstuff ;yes, back to main procedure lea TheVolume,a0 ;get our parameter block move.w SFReply+rVolume(a6),(a0);save VRefNum (or WDRefNum) lea SFReply+rName(a6),a0 ;copy the name lea TheFile,a1 ;byte by byte jsr copystr ;copy file name lea myparamblk(a6),a0 ;load parameter block move.w TheVolume,ioVRefNum(a0);WDRefNum into parameter block _SetVol ;set default volume clr.w -(SP) ;zero for normal sound and screen pea TheFile ;load application name move.l SP,A0 ;put it in a0 _Launch ;Launch away endofstuff: ;back for more (if we survived) unlk a6 jmp chicken copystr: ;copy a string pointed to by a0 clr.l d0 ;to one pointed to by a1 move.b (a0),d0 ;count byte copyit: move.b (a0)+,(a1)+ ;copy a byte dbra d0,copyit ;until no more rts ; ; ; Constant data area ; .ALIGN 4 STRING_FORMAT 0 MsgRect: dc.w 30,120,60,366 ;rectangle for messages SFPoint: DC.W 125,75 ;Point for standard file window MyTypelist: dc.b 'APPL' ;file types to launch ; STRING_FORMAT 3 ;Pascal standard strings TheVolume dc.w 0 TheFile dc.b 'This is one way to implement private storage!' ; ; If in an application, you may want to restore caller's registers, ; then RTS right here. ; chicken: dc.w $a9f4 ;done ; ; If you're writing a procedure/subroutine/function (are there ; any other names for it?) make "chicken:" an "rts" or something. ; It only gets executed in the event of a Cancel button (user ; chickened out!)