![]() |
WriteResource |
||||
Header: | Resources.h | Carbon status: | Supported | |
Writes resource data in memory immediately to a files resource fork.
void WriteResource ( Handle theResource );
A handle to a resource. The function checks the resChanged attribute of this resource. If the resChanged attribute is set to 1, such as after a successful call to the ChangedResource or AddResource function, WriteResource writes the resource data in memory to the resource fork, then clears the resChanged attribute in the resources resource map in memory.
If the resource is purgeable and has been purged, the function writes zero-length resource data to the resource fork. If the resources resProtected attribute is set to 1, the function does nothing, and the ResError function returns the result code noErr. The same is true if the resChanged attribute is not set (that is, set to 0). If the given handle isnt a handle to a resource, WriteResource does nothing, and ResError returns the result code resNotFound.
Note that this function does not write the resources resource map entry to disk.
When your application calls ChangedResource or AddResource, the Resource Manager attempts to reserve disk space for the changed resource. If the modified resource data cant be written to the resource fork (for example, if theres not enough room on disk), the resChanged attribute is not set to 1. If this is the case and you call WriteResource, the Resource Manager wont know that the resource data has been changed. Thus, the function wont write the modified resource data to the resource fork and wont return an error. For this reason, always make sure that the ResError function returns the result code noErr after a call to ChangedResource or AddResource.
The resource fork is updated automatically when your application quits, when you call the UpdateResFile function, or when you call the CloseResFile function. Thus, you should call WriteResource only if you want to write just one or a few resources immediately.
Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.
© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)