Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!rutgers!ucsd!hub!henri!doner From: doner@henri.ucsb.edu (John Doner) Newsgroups: comp.sys.mac.programmer Subject: Re: adding a document to the launch of an application? Keywords: beg grovel plead "pretty please" Message-ID: <3485@hub.UUCP> Date: 5 Jan 90 16:24:19 GMT References: <1085@crash.cts.com> Sender: news@hub.UUCP Reply-To: doner@henri.UUCP (John Doner) Organization: University of California, Santa Barbara Lines: 82 In article <1085@crash.cts.com> alen@crash.cts.com (Alen Shapiro) writes: >I think there was a thread a little while ago about how one should >add a document list to appparmhandle global area. I missed it!! > >Could someone mail me a summary please. I can launch an application I missed that thread too, but here's the source and documentation for a program I wrote a couple of years ago that does what you want, or something like it. This little program launches an application with a specified document. This is done by setting up the Finder Information, the data structure pointed to by the low-memory global AppParmHandle. Read about it in the Segment Loader chapter of IM. Apple provides routines for accessing the Finder Information, but none for creating it, since they thought that would always be done by the Finder. The Finder Information consists of two words giving a message and a count of the number of AppFile records following. Each record contains info on a file, including vRefNum, file type, and file name. This program has a STR# resource, ID 100, with three strings: the full pathname of the application to be launched, the full pathname of a file to be listed in the Finder Information, and the File Type of that file. It creates the Finder Information and launches the application. It oughtn't be hard to modify this so that multiple files could be listed in the Finder Information. And, you could just as well construct pathnames and get file types in some other way than reading them in from a resource. Note: The AppFile data structure is a record of which the last field is the filename, a Pascal string. These are declared as arrays of 256 bytes, and that's what you'll get if you create them in the normal way in Pascal or C. However, the assembly-coded Finder won't waste all that memory on short strings; instead each record begins right at the actual end of the string in the previous record. So you can't regard the Finder Information as an array of equal-sized records; you have to use the string length in one record to find the beginning of the next one. That's why one should use the Apple routines to access the Finder Information. #include "MacTypes.h" #include "HFS.h" #include "FileMgr.h" #include "SegmentLdr.h" #include "MemoryMgr.h" #include "ToolboxUtil.h" main() { int*ptr, i; char setParms; Str255volName, s; AppFile*p; union { unsigned char c[4]; OSType t; } theType; SetZone(SysZone); HUnlock(AppParmHandle); SetHandleSize( AppParmHandle,sizeof(AppFile)+4 ); if (MemError()) ReallocHandle( AppParmHandle, sizeof(AppFile)+4 ); setParms = !MemError(); HLock(AppParmHandle); SetZone(ApplZone); if (setParms) { p=(AppFile *)(*AppParmHandle+4); GetVol(volName,p->vRefNum); GetIndString(&s,100, 3); for (i=0;i<4;i++) theType.c[i] = s[i+1]; p->fType = theType.t; p->versNum = 0; GetIndString(&s,100,2); BlockMove(&s,&(p->fName),s[0]+1); ptr = (int *)*AppParmHandle; *(ptr++) = 0; *ptr = 1; } theLaunch: GetIndString(&s,100,1); Launch(0,s); }