Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Reading Resources Into Memory


GetNamedResource

You can use the GetNamedResource function to get a named resource.

FUNCTION GetNamedResource (theType: ResType; name: Str255)
                           : Handle;
theType
A resource type.
name
A name that uniquely identifies a resource of the specified type. Strings passed in this parameter are case-sensitive.
DESCRIPTION
The GetNamedResource function searches the resource maps in memory for the resource specified by the parameters theType and name. The resource maps in memory, which represent all the open resource forks, are arranged as a linked list. When GetNamedResource searches this list, it starts with the current resource file and progresses through the list in order (that is, in reverse chronological order in which the resource forks were opened) until it finds the resource's entry in one of the resource maps.

If GetNamedResource finds the specified resource entry in one of the resource maps and the entry contains a valid handle, the function returns that handle. If the entry contains a handle whose value is NIL, and if you haven't called SetResLoad with the load parameter set to FALSE, GetNamedResource attempts to read the resource into memory.

If the GetNamedResource function can't find the resource data, it returns NIL, and ResError returns the result code resNotFound. The GetNamedResource function also returns NIL if the resource data to be read into memory won't fit, in which case ResError returns an appropriate Memory Manager result code. If you call GetNamedResource with a resource type that can't be found in any of the resource maps of the open resource forks, the function returns NIL as well, but ResError returns the result code noErr. You should always check that the value of the returned handle is not NIL.

You can change the resource map search order by calling the UseResFile procedure before GetNamedResource.

SPECIAL CONSIDERATIONS
The GetNamedResource function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

RESULT CODES
noErr0No error
resNotFound-192Resource not found
SEE ALSO
To check for errors, call the ResError function as described on page 1-47.

To include ROM-resident system resources in the Resource Manager's search of the resource maps for open resource forks, use the RGetResource function as described on page 1-73.

For information about the UseResFile and SetResLoad procedures, see page 1-65 and page 1-74, respectively.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996

Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2004 Apple Computer, Inc.
All rights reserved. | Terms of use | Privacy Notice