Important: The information in this document is obsolete and should not be used for new development.
GetNamedResource
You can use theGetNamedResourcefunction 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
TheGetNamedResourcefunction searches the resource maps in memory for the resource specified by the parameterstheTypeandname. The resource maps in memory, which represent all the open resource forks, are arranged as a linked list. WhenGetNamedResourcesearches 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
GetNamedResourcefinds 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 isNIL, and if you haven't calledSetResLoadwith theloadparameter set toFALSE,GetNamedResourceattempts to read the resource into memory.If the
GetNamedResourcefunction can't find the resource data, it returnsNIL, andResErrorreturns the result coderesNotFound. TheGetNamedResourcefunction also returnsNILif the resource data to be read into memory won't fit, in which caseResErrorreturns an appropriate Memory Manager result code. If you callGetNamedResourcewith a resource type that can't be found in any of the resource maps of the open resource forks, the function returnsNILas well, butResErrorreturns the result codenoErr. You should always check that the value of the returned handle is notNIL.You can change the resource map search order by calling the
UseResFileprocedure beforeGetNamedResource.SPECIAL CONSIDERATIONS
TheGetNamedResourcefunction may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.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.To include ROM-resident system resources in the Resource Manager's search of the resource maps for open resource forks, use the
RGetResourcefunction as described on page 1-73.For information about the
UseResFileandSetResLoadprocedures, see page 1-65 and page 1-74, respectively.