Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!vaxeline!bootsie!olson From: olson@bootsie.uucp (Eric K. Olson) Newsgroups: comp.sys.mac.programmer Subject: Re: Is this possible with the Resource Manager? Message-ID: <1991Feb17.110259.12499@bootsie.uucp> Date: 17 Feb 91 11:02:59 GMT References: <1CE00001.ed5n0r@tbomb.ice.com> <1991Feb17.041728.11518@bootsie.uucp> Organization: Lexington Software Design, Lexington, MA Lines: 96 Well, I went ahead and brute-forced it. The following code allows me to load the Resource data off the disk, even if the resource is currently loaded and in use (such as 'MENU' resources of the currently running application). Unfortunately, it uses things that are likely to break: internal structures of the Resource Manager, and the TopMapHndl low-memory global. I don't know if these things are likely to change soon, or if they are available under AU/X. Isn't there a better way? Is this what AddReference() once did? typedef struct resMapHeaderRec { long dataOffset; long mapOffset; long dataLength; long mapLength; } resMapHeaderRec; typedef struct resMapRec { resMapHeaderRec header; struct resMapRec * * nextMap; short refNum; short attrib; unsigned short typeOffset; unsigned short nameOffset; } resMapRec, *resMapPtr, **resMapHandle; typedef struct resMapEntryRec { short resID; unsigned short nameOffset; unsigned long lengthOffset; Handle resHandle; } resMapEntryRec, *resMapEntryPtr, **resMapEntryHandle; Handle GetResDataFromDisk(type,id) ResType type; short id; { Handle onDiskHand; unsigned long resMapOffset; resMapEntryPtr resMapEntry; resMapPtr resMap; short inMemRef; Handle inMemHandle; SetResLoad(FALSE); inMemHandle = GetResource(type, id); SetResLoad(TRUE); if (*inMemHandle == NULL) { inMemRef = HomeResFile(inMemHandle); resMapOffset = RsrcMapEntry(inMemHandle); resMap = (resMapPtr) *TopMapHndl; /* Find the appropriate resource map */ while (resMap->refNum != inMemRef) { resMap = *(resMap->nextMap); if (resMap==NULL) return NULL; } resMapEntry = (resMapEntryPtr) (((Ptr) resMap) + resMapOffset); if (resMapEntry->resHandle!=inMemHandle) return NULL; DetachResource(inMemHandle); /* resMapEntry->resHandle = NULL; */ onDiskHand = GetResource(type, id); if (onDiskHand != NULL) { DetachResource(onDiskHand); HNoPurge(onDiskHand); } /* Reattach the old resource handle */ resMapEntry->resHandle = inMemHandle; } else { /* The normal GetResource case */ onDiskHand = GetResource(type, id); if (onDiskHand != NULL) { DetachResource(onDiskHand); HNoPurge(onDiskHand); } } } -- Eric K. Olson, Editor, Prepare() NOTE: olson@bootsie.uucp doesn't work Lexington Software Design Internet: olson@endor.harvard.edu 72A Lowell St., Lexington, MA 02173 Uucp: harvard!endor!olson (617) 863-9624 Bitnet: OLSON@HARVARD