Important: The information in this document is obsolete and should not be used for new development.
WriteResource
You can use theWriteResourceprocedure to write resource data in memory immediately to a file's resource fork. Note thatWriteResourcedoes not write the resource's resource map entry to disk.
PROCEDURE WriteResource (theResource: Handle);
theResource- A handle to a resource.
DESCRIPTION
Given a handle to a resource,WriteResourcechecks theresChangedattribute of that resource. If theresChangedattribute is set to 1 (after a successful call to theChangedResourceorAddResourceprocedure),WriteResourcewrites the resource data in memory to the resource fork, then clears theresChangedattribute in the resource's resource map in memory.
If the resource is purgeable and has been purged,
- Note
- When your application calls
ChangedResourceorAddResource, the Resource Manager attempts to reserve disk space for the changed resource. If the modified resource data can't be written to the resource fork (for example, if there's not enough room on disk), theresChangedattribute is not set to 1. If this is the case and you callWriteResource, the Resource Manager won't know that the resource data has been changed. Thus, the routine won't write the modified resource data to the resource fork and won't return an error. For this reason, always make sure that theResErrorfunction returns the result codenoErrafter a call toChangedResourceorAddResource.![]()
WriteResourcewrites zero-length resource data to the resource fork. If the resource'sresProtectedattribute is set to 1,WriteResourcedoes nothing, and theResErrorfunction returns the result codenoErr. The same is true if theresChangedattribute is not set (that is, set to 0). If the given handle isn't a handle to a resource,WriteResourcedoes nothing, andResErrorreturns the result coderesNotFound.The resource fork is updated automatically when your application quits, when you
callUpdateResFile, or when you callCloseResFile(which in turn callsUpdateResFile). Thus, you should callWriteResourceonly if you want to write just one or a few resources immediately.RESULT CODES
noErr 0 No error resNotFound -192 Resource not found SEE ALSO
To check for errors, call theResErrorfunction as described on page 1-47.For more information about resource attributes, see "The Resource Map" beginning on page 1-7. For descriptions of the
ChangedResourceandAddResourceprocedures,
see page 1-83 and page 1-85, respectively. For a description of theUpdateResFileprocedure, see page 1-87. For a description of theCloseResFileprocedure, see page 1-104.