Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!wuarchive!usc!apple!well!wdh From: wdh@well.sf.ca.us (Bill Hofmann) Newsgroups: comp.sys.mac.programmer Subject: Re: Problem with GetResource in a cdev Message-ID: <21923@well.sf.ca.us> Date: 2 Dec 90 18:50:51 GMT References: <48578@eerie.acsu.Buffalo.EDU> Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 39 In article <48578@eerie.acsu.Buffalo.EDU> volaski@acsu.buffalo.edu (Maurice Volaski) writes: >oldResFile=CurResFile(); /*save reference number to cdev's*/ > /*resources*/ >*resNum=HOpenResFile(vRefNum,dirID,fileName,fsRdWrPerm); /*open my file's > /*resource fork*/ >tempRes=GetResource('EXL ',-4048); /* GetResource succeeds here*/ >UseResFile(oldResFile); /* make cdev resource file current*/ >tempRes=GetResource('EXL ',-4048); /* PROBLEM: GetResource fails*/ >num=CountResources('EXL '); /* CountResources succeeds*/ >tempRes=GetIndResource('EXL ',1); /*GetIndResouces succeeds*/ > >Even though the file's resources are not current, GetResource should iterate >through the list of open resource files and find the resource. Interestingly, >CountResources and GetIndResource both succeed. Also, GetResource does >succeed when the file's resources are current. > >Anyone have a clue as to why GetResource fails in this particular instance? I'm suprised that CountResources and GetIndResource works. Here's the scenario: At the beginning of your code, the resource chain (the path the Resource Manager uses to search for resouces) is like so: ->cdev->DA Handler->System After the HOpenResFile, it's like so: ->fileName->cdev->DA Handler->System so naturally, if an 'EXL ' -4048 resource is in fileName, it succeeds. **THEN** you call UseResFile, it looks like *this*: | V fileName->cdev->DA Handler->System (pardon the sophisticated graphics). So naturally, GetResource fails if the only place an 'EXL ' -4048 resource is is in your file fileName. -Bill Hofmann