Microsoft KB Archive/51732

From BetaArchive Wiki
Knowledge Base

Article ID: 51732

Article Last Modified on 11/21/2006


  • Microsoft QuickBasic 1.0

This article was previously published under Q51732


This article describes how to list all of the resource types in a file, and how to get a list of all the ID numbers within a resource type.


The example below accesses the resource map of the opened resource file in order to get access to the type names and ID numbers.

Executing two PEEKLs at &HA50 will obtain the address of the resource map of the opened file. Using &HA54 will obtain the address to the system's resource map, and you do not have to open or close the System file because the system resource map is always in memory.

For a description of the resource map, please refer to Apple's "Inside Macintosh" Volume I (published by Addison-Wesley) starting on Page I-128.

Sample Code

' This program will open the resource of the file specified and
' will list all of the resource types in the resource map. It
' then allows you to choose a resource type and will list all the
' ID numbers in that type.

ref% = 0
OpenResFile "File Name", ref% ' Open the file whose resources
                              ' are to be looked at. Do not
                              ' open the System file.

Map& = PEEKL(PEEKL(&HA50))  ' This is the starting location
                            ' for the resource map of the
                            ' resource that was opened. Use
                            ' &HA54 instead of &HA50 to
                            ' obtain access to the system
                            ' resource map.

TypeList& = PEEKW(Map&+24)  ' The offset from the resource
                            ' map for the beginning of the
                            ' resource map's type list.

StartTypeList& = Map& + TypeList& ' The actual address for
                                  ' the type list.

NumType& = PEEKW(StartTypeList&) + 1 ' The number of types
                                     ' in the type list.
Sum$ = ""
PRINT "This the list of all the Resources in the Opened Resource"
PRINT "--------------------------------------------------"
StartList&=StartTypeList& + 2 ' The starting address for the
                              ' start of the type name list.

                         ' Read in each type and print it to
                         ' the screen with the corresponding
                         ' number the type is in the
                         ' resource map.:
FOR j = 1 TO NumType&
    FOR i = 0 TO 3       ' Each type can only be 4 bytes
                         ' (characters) long.
         Sum$ = Sum$ + CHR$(PEEK(StartList&+i))
    NEXT i

    PRINT j;" ";Sum$,
    IF (j MOD 4)= 0 THEN PRINT
    Sum$ =""
    StartList&= StartList& + 8

PRINT "--------------------------------------------";
PRINT "--------------"
PRINT "Please enter the Number corresponding to the";
PRINT "Resource Type -> ";
INPUT ResourceChoice%

                         ' Offset to the type name chosen.
NumResTypeOffset& = 6+ (8* (ResourceChoice%-1))

                         ' Address of the type name chosen.
TypeLoc& = NumResTypeOffset& + StartTypeList&

                         ' The number of ID numbers in the
                         ' resource type.
NumResType& = PEEKW(TypeLoc&) + 1

Sum$ =""
FOR i = 0 TO 3           ' Get the Name of the type chosen.
   Sum$ = Sum$ + CHR$(PEEK(TypeLoc& - 4 +i))

PRINT "The number of ID's in ";Sum$;" is: ";NumResType&

                         ' Offset to the list of ID numbers
                         ' from the beginning of the
                         ' resource map.
RefListOffset& = PEEKW(TypeLoc& + 2)

                         ' Starting address of the ID numbers
StartOfList& = StartTypeList& + RefListOffset&

PRINT "The list of ID's for this resource is :"
PRINT "--------------------------------"

FOR i = 1 TO NumResType& ' Print out the list of IDs.
   PRINT PEEKW(StartOfList& +( i * 12 )- 12)

PRINT "-----------------------------"
PRINT "Click on the Mouse Button to End"

CloseResFile ref%


Additional query words: MQuickB

Keywords: KB51732