home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20549 < prev    next >
Encoding:
Text File  |  1993-01-02  |  3.6 KB  |  112 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!att!princeton!pucc.Princeton.EDU!JIMPRYOR
  3. From: JIMPRYOR@pucc.Princeton.EDU (Jim Pryor)
  4. Subject: Launching one APPL from another
  5. Message-ID: <16B4A12F59.JIMPRYOR@pucc.Princeton.EDU>
  6. Originator: news@nimaster
  7. Sender: news@Princeton.EDU (USENET News System)
  8. Nntp-Posting-Host: pucc.princeton.edu
  9. Organization: Princeton University
  10. Date: Sun, 3 Jan 1993 02:34:17 GMT
  11. Lines: 99
  12.  
  13. Could someone who understands the mechanics of launching an application
  14. from another application take a look at the following code, and tell
  15. me what I'm doing wrong? The launching works fine, but several
  16. programs initialize strangely when launched this way. ResEdit says that
  17. it's corrupted (but launches fine directly); various other programs are
  18. unable to find their preferences files (especially programs that store
  19. their preferences in the directory the application resides in, rather
  20. than in the System Folder).
  21. I imagine the trouble comes from the HSetVol call, but I'm not
  22. sure why; and I don't know how to get around it (PBHSetVol would
  23. probably yield the same results, but I haven't tried it). How else
  24. would the assembly launch routines be able to locate the application,
  25. since they're only provided with the name?
  26. BTW, the assembly code is derived from a DA skeleton for launching programs
  27. that I found on one of the archives (sumex-aim or wuarchive). Sorry for
  28. the lack of attribution, but I've lost the original file.
  29.  
  30. Please respond by e-mail: jimpryor@pucc.princeton.edu
  31. I'll summarize replies if anything turns up.
  32.  
  33. --- Code follows ---
  34.  
  35. program alias;
  36.   type
  37.     plaunchrec = ╪launchrec;
  38.     launchrec = record
  39.         pfname: ╪str255;
  40.         param: integer;
  41.       end;
  42.     aka_h = ╪aka_p;
  43.     aka_p = ╪aka_rec;
  44.     aka_rec = record
  45.         dirID: longint;
  46.         fname: str255;
  47.       end;
  48.  
  49.   procedure execlaunch;
  50.   inline
  51.     $a9f2;
  52.   procedure initlaunch (plaunch: plaunchrec);
  53.   inline
  54.     $205f;  {move.l (a7)+, a0}
  55.  
  56.   var
  57.     aka: aka_h;
  58.     fname: str255;
  59.     fvol: integer;
  60.     res: oserr;
  61.     dir: longint;
  62.     info: finfo;
  63.     launch: launchrec;
  64.     x: integer;
  65.     v, f: str255;
  66.     s: signedbyte;
  67.     hfp: hparamblockrec;
  68.  
  69. begin
  70. {read 'AKA:' resource #1, which stores "hard" Directory ID}
  71. {in a long integer, followed by a pascal string padded to 63 bytes}
  72.   aka := aka_h(getresource('AKA:', 1));
  73.   if aka = nil then
  74.     debugstr('''AKA:'' resource #1 not found.');
  75. {see if file stored in 'AKA:' resource exists}
  76.   f := aka╪╪.fname;
  77.   hfp.iodirid := aka╪╪.dirid;
  78.   hfp.ionameptr := @f;
  79.   res := pbhgetfinfo(@hfp, false);
  80.   if res <> noerr then
  81.     begin
  82. {ask user to locate file}
  83. {if sfgetfile not cancelled, update 'AKA:' resource}
  84.       s := hgetstate(handle(aka));
  85.       hnopurge(handle(aka));
  86.       f := aka╪╪.fname;
  87.       paramtext(concat('Please find ''', f, ''''), '', '', '');
  88. {custom getfile routine, in separate unit; displays paramtext ╪0}
  89. {returns true if and only if reply.good}
  90.       if not getsfile(fname, fvol, 'APPL', 1) then
  91.         exittoshell;
  92.       res := setvol(nil, fvol);
  93.       res := hgetvol(@v, x, dir);
  94.       aka╪╪.dirID := dir;
  95.       aka╪╪.fname := fname;
  96.       changedresource(handle(aka));
  97.       if reserror = noerr then
  98.         writeresource(handle(aka))
  99.       else
  100.         sysbeep(10);
  101.       hsetstate(handle(aka), s);
  102.     end;
  103. {I susupect this (unrecommended) use of hgetfile is the culprit:}
  104. {maybe the launched programs expect the default volume to be the}
  105. {root directory...}
  106.   res := hsetvol(nil, 0, aka╪╪.dirID);
  107.   launch.pfname := @aka╪╪.fname;
  108.   launch.param := 0;
  109.   initlaunch(@launch);
  110.   execlaunch;
  111. end.
  112.