FB II Compiler
Get the volRefNum of a resource file
Anybody know how to get the file name and/or volRefNum of an open resource? Like if I get a res handle using GETNAMEDRESOURCE and I want to find the file that the resource actually lives in (it's not part of my application). Any ideas?
Yes, sort of. The Mac filesystem deals with open files as 16-bit integers (the % kind). Though this detail is hidden from you by the FB runtime, each open file has a unique file reference number which is used in most file operations.
Mac files, as you know, have two forks. From the user's point of view, these are two data areas for one file. But to the filesystem, they are two separate files that just happen to have the same name and live in the same folder. The actual data may live in completely different places on disk.
So there is one reference number for the datafork-file and one reference number for the resourcefork-file. The reference number for the resource fork *is* the resource reference number returned by OpenResFile and OpenRFPerm. Once you have an open-file reference number, you can use PBGetFCBInfo to extract the file's name, volume, parent directory, size, ID, and other stuff.
In conclusion: Yes, a resRefNum and a fileRefNum are different beasts - but they are the same KIND of beast.