alen@crash.cts.com (Alen Shapiro) (01/05/90)
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 but I want to give it a document to open automatically on launch and I'm totally confused by inside mac. On a related note. Is there a high-level method for finding the correct application to launch from a document's signature. So far all I can think to do is open all the desktop files (one per mounted volume) and try to find the signature in the APPL resource. If it's there then I think the app is present on that volume. What I do from there is a mystery. TIA --alen the Lisa slayer (it's a long story) ...alen%shappy.uucp@crash.cts.com (a mac+ uucp host- what a concept!!) ...alen@crash.cts.com
doner@henri.ucsb.edu (John Doner) (01/06/90)
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); }
zben@umd5.umd.edu (Ben Cranston) (01/06/90)
In article <5872@umd5.umd.edu> zben@umd5.umd.edu (Ben Cranston) blathers: > One of the three words in the APPL resource is a link to the BNDL resource, > which then has links to the ICN# and FREF resources. I must have been high on fatigue poisons while writing that. I meant that the third word of the creator-ID resource contains the link to the bundle. Looks like all you have to do is open a WD on the directory ID in the APPL resource, then set that as the current volume, then do a Launch on the name in the APPL resource. The following information on how to find the ICON is included here for reference: Desktop File Notes: The APPL resource contains triples of creator-ID, directory number, and string filename for each application present on the desktop's volume. For example, MacWrite's creator-ID is MACA. Somewhere in the APPL resource there will be a record: MACA 20 MacWrite 5.01 This tells the finder to SetWD to a WD on directory ID 20 and then Launch MacWrite 5.01 in order to execute the application. The desktop file also contains a resource with the creator-ID as its resource ID (the resource number is always zero). The first four bytes seem to be constant (77231199?) but the last two bytes contain a link to the Finder's copy of the application's bundle resource. For example: MACA(0) 7723 1199 109D w#DoDu ---- Hexadecimal 109D is decimal 4253. Sure enough, there is a bundle resource with that number, that is a (relocated) copy of MacWrite's bundle: BNDL(4253) ICN# 1 7453 2 23840 3 15699 4 12586 FREF 1 28330 2 9671 3 29598 4 32610 These are the relocated ICN# and FREF resources as they appear in the desktop file. For example: FREF(9671) WORD 2 This says a document of creator-ID MACA and file type WORD should appear as relative icon number two. Tracking back through the bundle, we find that the appropriate icon is stored in ICN# 23840 in the desktop file. Gee, thanks for mentioning it. I didn't even KNOW there was an APPL resource till you asked about it! -- Sig DS.L ('ZBen') ; Ben Cranston <zben@Trantor.UMD.EDU> * Network Infrastructures Group, Computer Science Center * University of Maryland at College Park * of Ulm