Important: The information in this document is obsolete and should not be used for new development.
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 forFSSpecrecords and partial resources), use theGestaltfunction.Two commonly used Resource Manager routines use a file system specification (
FSSpec) record: theFSpCreateResFileprocedure and theFSpOpenResFilefunction. These routines are available only in System 7 or later. Call theGestaltfunction with thegestaltFSAttrselector to determine whether the Resource Manager routines that useFSSpecrecords exist. If the bit indicated by the constantgestaltHasFSSpecCallsis 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 theGestaltfunction to determine whether these features are available. Call theGestaltfunction with thegestaltResourceMgrAttrselector to determine whether the routines for handling partial resources exist. If the bit indicated by the constantgestaltPartialRsrcsis set, then the Resource Manager routines for handling partial resources are available. For more information about theGestaltfunction, 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 theResErrorfunction 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 theResErrorfunction to determine whether an error occurred.Resource Manager functions usually return
NILor -1 as the function result when there's an error. For Resource Manager functions that return -1, your application can call theResErrorfunction 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 isNIL. If it is, your application can useResErrorto obtain specific information about the nature of the error. Note, however, that in some casesResErrorreturnsnoErreven though the value of the returned handle isNIL.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.
- get a handle to a resource and modify a purgeable resource safely
- release and detach resources
- create and open a resource fork
- set the current resource file (the file whose resource fork the Resource Manager searches first)
- read and manipulate resources
- write resources
- read and write partial resources
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