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 / Resource Manager Reference
Resource Manager Routines / Writing to Resource Forks


WriteResource

You can use the WriteResource procedure to write resource data in memory immediately to a file's resource fork. Note that WriteResource does 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, WriteResource checks the resChanged attribute of that resource. If the resChanged attribute is set to 1 (after a successful call to the ChangedResource or AddResource procedure), WriteResource writes the resource data in memory to the resource fork, then clears the resChanged attribute in the resource's resource map in memory.

Note
When your application calls ChangedResource or AddResource, 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), the resChanged attribute is not set to 1. If this is the case and you call WriteResource, 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 the ResError function returns the result code noErr after a call to ChangedResource or AddResource.
If the resource is purgeable and has been purged, WriteResource writes zero-length resource data to the resource fork. If the resource's resProtected attribute is set to 1, WriteResource 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 isn't a handle to a resource, WriteResource does nothing, and ResError returns the result code resNotFound.

The resource fork is updated automatically when your application quits, when you
call UpdateResFile, or when you call CloseResFile (which in turn calls UpdateResFile). Thus, you should call WriteResource only if you want to write just one or a few resources immediately.

RESULT CODES
noErr0No error
resNotFound-192Resource not found
SEE ALSO
To check for errors, call the ResError function 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 ChangedResource and AddResource procedures,
see page 1-83 and page 1-85, respectively. For a description of the UpdateResFile procedure, see page 1-87. For a description of the CloseResFile procedure, see page 1-104.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996