ReadPartialResource
ReadPartialResource Get a handle to part of a resource
#include <Resources.h> Resource Manager
void ReadPartialResource(theResource, offset, buffer, count);
Handle theResource ; 4-byte ResType; resource type to get
long offset ; start of section to be obtained
Ptr buffer ; buffer to contain the partial resource
long count ; length of section
You can use the ReadPartialResource and WritePartialResource
procedures to manipulate a subsection of a large, unwieldy resource that may
not otherwise fit in memory. You can use the SetResourceSize procedure to
change the size of a resource on disk to a size that you specify.
Be aware that having a copy of a resource in memory when you are using the
partial resource routines may cause problems. If you have modified the copy in
memory and then access the resource on disk using either the
ReadPartialResource or WritePartialResource procedure, you will
lose changes made to the copy in memory.
The ReadPartialResource procedure reads part of a resource in from disk,
which allows you to work with small portions of large resources. This
procedure reads into memory a section of the resource, which is specified by
the parameter theResource. The value of the offset parameter marks the
beginning of the subsection as measured in bytes from the start of the
resource. The length of the section is given by the value of the count parameter.
The ReadPartialResource procedure reads the partial resource into the
buffer you indicate with the buffer parameter. You are responsible for the
memory management of this buffer. You cannot use the ReleaseResource
procedure to release the memory occupied by this buffer. Call the ResError
function to check for errors.
The ReadPartialResource procedure always tries to read resources from
the disk. If a resource is already in memory, the Resource Manager still
reads it from the disk and ResError returns the resourceInMemory result
code. If you have loaded the resource into memory and modified it, you will lose
any changes to the resource once you call the ReadPartialResource
procedure. If you try to read past the end of a resource or your offset is out of
bounds, ResError returns the inputOutOfBounds error. If the handle named
by the parameter theResource is not in any open resource files, ResError
returns the resNotFound result code.
When using partial resource routines, you should call the SetResLoad
procedure specifying FALSE for its load parameter before you call the
GetResource function. SetResLoad prevents the Resource Manager from
reading the entire resource into memory. Be sure to restore the normal state
of the SetResLoad procedure after you call the GetResource function.
Note: If the resource is in memory and you want part of its data, you
should use the BlockMove procedure instead of the
ReadPartialResource procedure, because BlockMove is faster.
Returns: an Error Code. It will be one of:
resourceInMemory (-188) Resource already in memory
inputOutOfBounds (-190) Offset or count out of bounds
resNotFound (-192) Resource not found