Microsoft KB Archive/51731

= How to List All STR# Resources as GetIndString & GetString Do =

Article ID: 51731

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for 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 &quot;Inside Macintosh&quot; 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. (&quot;Inside Macintosh&quot; 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 &quot;File Name&quot;,ref% ' You can open a file resource instead ' of using the System's. GetRes ref%,&quot;STR#&quot;,id%,H&     ' Get handle to the resource STR#. LockRes H&                    ' Lock the Handle to STR#, so another ' application cannot use it. PRINT &quot;This is the list of the strings in the resource STR#&quot; PRINT &quot;---&quot; 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$= &quot;&quot; IF NumStrings% > 1 THEN       ' Get each string and print it  FOR i% = 1 TO NumStrings%    ' on the screen. TheString$ =&quot;&quot; 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 &quot;---&quot; PRINT &quot;Click on the Mouse to Continue&quot; WHILE MOUSE(0) <> 1 : WEND ReleaseRes H&                 ' Release the STR# handle. 'CloseResFile ref%  ' Only use this if you used OpenResFile above. END

Additional query words: MQuickB

Keywords: KB51731

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.