volaski@acsu.buffalo.edu (Maurice Volaski) (12/01/90)
In a cdev, I open the resource fork of a file and attempt to read one of its resources. However, GetResource returns a nil handle indicating it is unable to find the resources of the specified type. ResError and MemError both return 0. 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? Maurice Volaski
russotto@eng.umd.edu (Matthew T. Russotto) (12/02/90)
In article <48578@eerie.acsu.Buffalo.EDU> volaski@acsu.buffalo.edu (Maurice Volaski) writes: >In a cdev, I open the resource fork of a file and attempt to read one of >its resources. However, GetResource returns a nil handle indicating it >is unable to find the resources of the specified type. >ResError and MemError both return 0. > >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? > >Maurice Volaski Believe it or not, all of the above is documented, correct, behavior. ResErr is 0 because there are no resources of type 'EXL ' in any resource file searched by GetResource-- this is a long-standing documented 'feature' of GetResource. GetResource does not search files opened after the current resource file. This is also documented, correct behavior. CountResources and GetIndResource don't respect the current resource file, and instead search all open resource files. This is also documented, correct behavior. Look at Inside Mac Volume I, pages 118-119. -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu .sig under construction, like the rest of this campus.
wdh@well.sf.ca.us (Bill Hofmann) (12/03/90)
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: <START HERE>->cdev->DA Handler->System After the HOpenResFile, it's like so: <START HERE>->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*: <START HERE> | 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