How to List All STR# Resources as GetIndString & GetString Do (51731)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0

This article was previously published under Q51731

SUMMARY

This article describes how to access all the strings in the STR# resource in the System file. The sample program displays all the strings in a given ID number to the screen. The program uses GetRes (an MBLC routine built into QuickBASIC) and PEEK functions.

The program below gives you an alternative to executing the GetString and GetIndString toolbox calls, which are listed in Apple's "Inside Macintosh" Volume I (published by Addison-Wesley). You cannot directly call GetString and GetIndString from QuickBASIC, because QuickBASIC's ToolBox statement can't call routines that are not in ROM. ("Inside Macintosh" indicates which routines are or aren't in ROM.) You would normally need to call C or another language from QuickBASIC to invoke GetString and GetIndString.

MORE INFORMATION

The example below gets the resource handle for the STR# resource from the System file. The handle is used to point to where the strings are loaded into memory. Instead of using the System file, you could open a file's resource fork to obtain access to a file's STR# resource(s).

PEEKing at the first word at the handle's location obtains the number of strings located in the STR# ID opened. PEEKing at two bytes after the handle obtains the length of the first string. The string will be stored right after its length. Subsequent strings are stored in the same manner, following the first string.

Sample Code

ref% = 0    ' Zero can be used as the System's file-reference number.
            ' No OpenResFile statement is necessary, since the
            ' resource fork of the System file is always open.
id% = IDNumber ' The ID number associated with the STR# you wish to
               ' look at.
H& = 0
'OpenResFile "File Name",ref%  ' You can open a file resource instead
                               ' of using the System's.
GetRes ref%,"STR#",id%,H&      ' Get handle to the resource STR#.
LockRes H&                     ' Lock the Handle to STR#, so another
                               ' application cannot use it.
PRINT "This is the list of the strings in the resource STR#"
PRINT  "---------------------------------------------------"
PRINT
StartSTR&=PEEKL(H&)            ' Get the starting address of where
                               ' resource STR# is located in memory.
NumStrings% =  PEEKW( StartSTR& ) ' Get the number of strings
                                  ' stored in the STR# list.
OffSet% =0
TheString$= ""
IF NumStrings% > 1 THEN        ' Get each string and print it
  FOR i% = 1 TO NumStrings%    ' on the screen.
     TheString$  =""
     Length% = PEEK( StartSTR& +2+OffSet%)  ' The length of the string
     FOR j% = 1 TO PEEK( StartSTR& + 2 + OffSet%)
      TheString$ = TheString$ + CHR$(PEEK(StartSTR& +2+ OffSet%+ j% ))
     NEXT j%
     OffSet%=OffSet% + Length% + 1
     PRINT TheString$
  NEXT i%
END IF
PRINT
PRINT "---------------------------"
PRINT "Click on the Mouse to Continue"
WHILE MOUSE(0) <> 1 : WEND
ReleaseRes H&                  ' Release the STR# handle.
'CloseResFile ref%   ' Only use this if you used OpenResFile above.
END
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB51731