Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager


Using the Resource Manager

You use the Resource Manager to perform operations on resources. To determine whether certain features of the Resource Manager are available (support for FSSpec records and partial resources), use the Gestalt function.

Two commonly used Resource Manager routines use a file system specification (FSSpec) record: the FSpCreateResFile procedure and the FSpOpenResFile function. These routines are available only in System 7 or later. Call the
Gestalt function with the gestaltFSAttr selector to determine whether the Resource Manager routines that use FSSpec records exist. If the bit indicated by the constant gestaltHasFSSpecCalls is set, then the routines are available.

CONST
   gestaltFSAttr           = 'fs  ';   {Gestalt selector for }
                                       { File Mgr attributes}
   gestaltHasFSSpecCalls   = 1;        {check this bit in the }
                                       { response parameter}
In addition, the Resource Manager routines for reading and writing partial resources are available only in System 7 or later versions of system software. Use the Gestalt function to determine whether these features are available. Call the Gestalt function with the gestaltResourceMgrAttr selector to determine whether the routines for handling partial resources exist. If the bit indicated by the constant gestaltPartialRsrcs is set, then the Resource Manager routines for handling partial resources are available. For more information about the Gestalt function, see Inside Macintosh: Operating System Utilities.

CONST
   gestaltResourceMgrAttr  = 'rsrc';   {Gestalt selector for }
                                       { Resource Mgr attributes}
   gestaltPartialRsrcs     = 0;        {check this bit in the }
                                       { response parameter}
You can use the ResError function to retrieve errors that may result from calling Resource Manager routines. Resource Manager procedures do not report error information directly. Instead, after calling a Resource Manager procedure your application should call the ResError function to determine whether an error occurred.

Resource Manager functions usually return NIL or -1 as the function result when there's an error. For Resource Manager functions that return -1, your application can call the ResError function to determine the specific error that occurred. For Resource Manager functions that return handles, your application should always check whether the value of the returned handle is NIL. If it is, your application can use ResError to obtain specific information about the nature of the error. Note, however, that in some cases ResError returns noErr even though the value of the returned handle is NIL.

The rest of this section describes how to create a resource using ResEdit or the Rez resource compiler. It then describes how to use Resource Manager routines to

For detailed descriptions of all Resource Manager routines, see "Resource Manager Reference" beginning on page 1-36. For information on writing data to a file's data fork, see Inside Macintosh: Files.


Subtopics
Creating a Resource
Getting a Resource
Releasing and Detaching Resources
Opening a Resource Fork
Reading and Manipulating Resources
Writing Resources
Working With Partial Resources

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996