Using the Resource Manager
resource into memory or write a block of data to a resource stored on disk,
even if the size of the memory you have to work in is smaller than the entire
resource. You can also change the size of a resource on disk.
Using Partial Resources
Some resources, such as the 'snd ' and 'sfnt' resources, can be quite
large-larger, in fact, than the memory available. The partial resource
routines in System 7.0 allow you to read a portion of the resource into memory
or alter a section of the resource while it is still on disk. You can also enlarge
procedure reads a portion of a resource from disk into memory, and the
disk. You can also change the size of the resource on disk to any desired size,
routines, you specify how far into the resource you want to begin reading or
writing and how many bytes you actually want to read or write at that spot, so
you must be sure of the location of the data.
Warning: Be aware that having a copy of a resource in memory when you
are using the partial resource routines may cause problems. If you have
modified the copy in memory and then access the resource on disk using
procedure, you will lose changes made to the copy in memory .
To read or write any part of a resource, call the SetResLoad procedure function to get an empty handle to the resource. (Because of the call to the
resource into memory.) Use the ResError function to check for errors. To check for the existence of the new partial resource routines, use the
Gestalt function with the gestaltResourceMgrAttr selector. This selector returns a range of bits, the meaning of which must be determined by
comparison with a list of constants. If the bit defined by the constant
gestaltPartialRsrcs is set, the partial resource routines are available.
The Listing below illustrates one way to deal with partial resources. This
procedure begins with a call to the SetResLoad procedure. A handle to the resource from which you want to read is put into the myResHdl variable. If
there is no error on the call to the GetResource function, a call is made to are no errors with this call, you exit the procedure. DoError is the name of
your routine that handles and processes errors.
Using partial resource calls
// Assuming inclusion of MacHeaders
// Prototype routine like this prior to calling it
void ReadAPartial(long, long, Ptr *); void ReadAPartial(long start, long count, Ptr *PutItHere) {
short myRsrcID; // id of resource
Handle myResHdl; // handle to resource // error variables
// prototype error handling procedure
SetResLoad(FALSE); // do not load resource // Set up myRsrcType and myRsrcID to your liking.
resErr = ResError();
SetResLoad(TRUE); // reset to always load if ( !resErr ) { // GetResource returned successfully
// Check and report error.
if ( RPRErr )
DoError(RPRErr);
}
DoError(resErr);
}
Creating and Opening Resource Files
System 7.0 introduces a simple, standard format for identifying a file or
directory, the file system specification (FSSpec) record. This record contains the volume reference number of the volume on which a file or
directory resides, the directory ID of the parent directory, and the name of the
file or directory.
create resource files for files or directories named by the file system
specification record.
If you want to open or create resource files under the Hierarchical File
System (HFS) but are not using the file system specification record in your
procedure.
Storing Fonts in a Resource Fork
Storing a font in an application's resource fork can create serious problems
for a user who tries to print a document in that font when background printing
is on. Never store fonts in a document's resource fork, since this can cause
heap corruption. If you feel that a document needs to have a particular font
available, you should license it for distribution and let users install it in their
System files.
If you use a font as a way to store symbols that your application uses in a
palette or for some other special purpose, use a font family ID in the range
assigned for uninterpreted symbols. (For more information about font family
and script systems, see the Worldwide Software Overview