Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!genrad!decvax!dartvax!earleh From: earleh@dartvax.UUCP (Earle R. Horton) Newsgroups: comp.sys.mac Subject: Re: How to launch an application Message-ID: <6062@dartvax.UUCP> Date: Fri, 24-Apr-87 04:42:53 EDT Article-I.D.: dartvax.6062 Posted: Fri Apr 24 04:42:53 1987 Date-Received: Sun, 26-Apr-87 20:37:06 EDT References: <1405@uwmacc.UUCP> <3326@linus.UUCP> Organization: Society for the Prevention of Cruelty to Graduate Students Lines: 183 Keywords: launch Summary: Here you go. In article <3326@linus.UUCP>, jkm@security.uucp (Jonathan K.Millen) writes: > In article <1405@uwmacc.UUCP> pwu@uwmacc.UUCP (Peter Wu) writes: > >Can someone show me how to launch an application from an assembly > >program? Thanks. > > > I hope an answer to that is posted, especially if it shows how to tell > the application the name of an application to open. Inside Mac is very > hard to follow on this. > > -Jon Millen > "We should stand on the shoulders of those > decvax!linus!security!jkm who have gone before us, not on each > jkm@mitre-bedford.arpa other's toes." Launch is a lot of fun. Here is a complete desk accessory example of how to do it. With minimal work, this can be incorporated into the code of an application... There are some points to be noted here. The first is it is more trouble to get the file name of the application than to do the launch itself! It is perhaps a good idea to flush all volumes before calling launch, and it is required to "_SetVol" to the correct volume before doing so. The last I can think of is: my "doflush" routine destroys the contents of A3, meaning it is perhaps NOT a good choice for a standalone routine to be called from Basic or Pascal. I heartedly agree with Jon's motto! I included the binhex of the desk accessory for non-programmer types. include mds:library:Pushpop.txt ;push and pop macros include mds:library:Packages.txt ;Macintosh package macros include mds:library:NewLib.D ;assembler equates IOFVersNum EQU 26 myparamblk equ -80 ;stack frame offsets otherparamblk equ -160 SFReply equ -240 saveport equ -4 thetype equ -6 itemhandle equ -8 thebox equ -16 filtervars equ -16 ; ;Earle Horton's Transfer DA ; OrnEntry DC.W $0400 ; ctl-enable only DC.W 0 ; doesn't need time DC.W $0040 ; update events only DC.W 0 ; no menu DC.W Launch1-OrnEntry ; open routine DC.W Dummy-OrnEntry ; prime - unused DC.W Dummy-OrnEntry ; control DC.W Dummy-OrnEntry ; status - unused DC.W Dummy-OrnEntry ; close Dummy: rts ; ; To use in an application, uncomment the next line and cut out ; all the desk accessory stuff, then assemble and link to your ; application. (After you have hacked the code to your taste, ; of course.) Suggested calling procedure: ; extern Launch1(); ; Launch1(); ; Or, from assembler: ; xref Launch1 ; jsr Launch1 ; ; xdef Launch1 Launch1: link a6,#-240 ;get a stack frame push.l SFPoint ;box coordinates clr.l -(sp) ;no prompt string pea fakefilter ;not a real file filter 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 bsr doflush ;flush all disk buffers first ;in case some application forgot lea myparamblk(a6),a0 ;load parameter block clr.l ioVNPtr(a0) ;clear volume name move.w SFReply+rVolume(a6),ioVRefNum(a0) ;load WDRefNum instead clr.w ioFDirIndex(a0) ;clear directory index field clr.w IOFVersNum(a0) ;clear file version field _SetVol ;launch on correct volume! clr.w -(SP) ;zero for normal sound and screen lea SFReply+rName(a6),a0 ;load name pointer move.l a0,-(sp) ;push it move.l SP,A0 ;put it in a0 _Launch ;Launch away endofstuff: ;second thoughts unlk a6 rts fakefilter: ;This is not a file filter. It is just a procedure to ;change the title of the SFGetFile box's open button. ;The button might flash a little bit if a whole bunch ;of applications are found. It probably would be better ;to use some private storage to remember if this routine ;had been called before. link a6,#filtervars ;get a stack frame pea saveport(a6) ;push a handle _GetPort ;get a handle to SFGetFile box port push.l saveport(a6) ;push the port push.w #1 ;item #1, the open button pea thetype(a6) ;address of item type pea itemhandle(a6) ;address of item handle (want this) pea thebox(a6) ;address of item's rect _GetDItem ;get the item push.l itemhandle(a6) ;push the item handle pea runmsg ;our title of open button _SetCTitle ;set it unlk a6 ;done for now move.w #0,8(sp) ;display OK move.l (sp)+,(sp) ;move return -> parameter rts ;exit doflush: ;This piece of code flushes all online volumes in ;preparation for the launch. It does NOT write out ;any data that the open application had been planning ;to write to any open files. (How could it?) move.l VCBQHdr+2,a3 ;a3 -> VCB entry scan: tst.w VCBDrvNum(a3) ;volume on line? beq.s nextone ;no, get next lea myparamblk(a6),a0 ;a0 -> stack frame parameter block move.l VCBVN(a3),ioVNPtr(a0) ;set volume name clr.w ioVDrvNum(a0) ;clear drive number _FlushVol ;flush it nextone: move.l (a3),a3 ;a3 -> next in chain move.l a3,d1 ;move to D1 (just testing) bne.s scan ;try again rts ; ; ; Constant data area ; .ALIGN 4 STRING_FORMAT 0 SFPoint: DC.W 100,75 ;Point for standard file window MyTypelist: dc.b 'APPL' ;file types to launch ; STRING_FORMAT 3 ;Pascal type strings runmsg dc.b 'Run' ------------------------------------------------------------------ linker command file to generate the code for the DA ------------------------------------------------------------------ [ /Output mds:transfer_folder:TransferDA mds:Transfer_folder:TransferDA $ ------------------------------------------------------------------ RMaker command file to make it into a 'DRVR' ------------------------------------------------------------------ *Output file name and the Type and Creator flags mds:TransferDeskAcc DFILDMOV * TYPE DRVR = PROC Launch,16 mds:Transfer_folder:TransferDA ------------------------------------------------------------------ Just in case, the binhex file. ------------------------------------------------------------------ (This file must be converted with BinHex 4.0) :$e4bB@jcCQ9b4'9cDd&MB`"%4NP-4%e29J#3#!)4phd!N!3"!*!$!GJ!N!2B!*! $13F""`%(!3F""`%(!3F#"3%&!38""3%(!3F""`%(!3F"$e4bB@jcCQ9b4'9cDd& MB`)!N$'FY*1'!*!'!K%(!3S""3%)!3N"#!%)!JS)#!%*!3N"#!%-!3X""J%*!3F ""`%%!33""`%*!3J"$`!+!*!'"qU3!!#3"0N!"J!!rrF!"J!,!a)!#3!#!*!$-`# 3-Y3%!*!%3!#3!a3!%J!5!")!%Nje6PEr%#mk!+T#TdKk!%Sr2!!"5(S!S%+R5'l r%$mm!!+TkNTZra"R!!!U6VS!B%(Zrl"#U!!5-@lr&J!@3QJ!(%*S!"UJ&8*R3Hl r'Lm))%qTmNjH6R919[r`5'lrr+Kd,blrr$mm!!&)E[rk5'lrq%KZrr#TM5mZrrK )HJ!mU9p1AMpm!*!$##kI6R8QH!0B5QX!5'F33HlrX#&V!#`!%N*S!"DJ%bC6)JY Qj%je!*!$C!",39"36!05G@i$8R9Z!!!"!*!$!GJ!N!2B!*!$13!!rb3"f!#3!a` !-J!!4&*@8J#3!`S!%!#3#JC-BA9ZBfJfb`: ------------end of transmission------------