version 2003
PA_GetIndexedResource (resfile; kind; index; data) long
Parameter | Type | Description | |
resfile | short | File reference number of the file to access | |
kind | unsigned long | Kind (4 Bytes type) of the resource access by index | |
index | short | xTh resource of type kind | |
data | char* | Resource data | |
Function result | long | Size of the received data in bytes |
Description
The routine PA_GetIndexedResource reads the indexTh resource of type kind in the file resFile, fills the data pointed to by resData with the content of the resource, and returns its size in bytes.
Pass the file reference number of the file that holds the resource in resFile .
Pass in kind the 4-Bytes type code of the resource (such as 'PICT' or 'TEXT').
index is a positive value in the range 1 to PA_CountResources. Note that the order is kept by the Internal Resource Manager and is arbitrary - it is not the order of creation of the resources.
Pass a pointer to the block of memory that holds the new data of the resource in newData, and the size of this data in bytes in dataSize.
To get the size of the resource (to pre-allocate a buffer at the current size), first call the routine passing 0L in resData. Then allocate the buffer at the correct size and call the routine again.
If index is out of range or if resFile is an invalid file reference number, the routine returns 0, leaves the data pointed to by resData unchanged and PA_GetLastError returns -5 ("Resource not found").
Example
Loop on all the resources of a particular kind (no error checking here).
void ApplyToAllResources (short resFile, unsigned long kind) { char *resData; long i, count, size; count = PA_CountResources(resFile, kind); for(i = 1; i <= count; i++) { size = PA_GetIndexedResource(resFile, kind, i, 0L); res = malloc(size); size = PA_GetIndexedResource(resFile, kind, i, resData); /* . . . do something with this resource . . . */ free(res);; } }
See Also
PA_CountResources, PA_GetResource.
Error Handling
Use PA_GetLastError to see if an error occurred