Microsoft KB Archive/36080

= SYSTEM(7) or OpenResFile Gives Resource File Reference Number =

Article ID: 36080

Article Last Modified on 11/21/2006



This article was previously published under Q36080



SUMMARY
A &quot;resource file reference number&quot; is a number that allows you to access the resource fork (area) of a file. Many of QuickBASIC's MBLC routines use this number to access stored resources. This number is neither an index nor a pointer -- it only has meaning to the Macintosh System.

You can obtain a resource file reference number using the following two methods in Macintosh QuickBASIC:   Use the QuickBASIC SYSTEM(7) function. The SYSTEM(7) function returns the file reference number (ref%) of the currently-running compiled application or the currently-running interpreted source file: ref% = SYSTEM(7) Never use CloseResFile on the number returned by SYSTEM(7).   Use the OpenResFile Toolbox library routine to open external resource files. In the following example, the OpenResFile statement returns the file reference number of the &quot;Demo Resources&quot; file in the variable ref%: ref% = 0     '  must initialize ref% before calling OpenResFile OpenResFile &quot;Examples:QB Demos:Demo Resources&quot;,ref% ' ... put the body of your program here ... ' In the interpreter, the program must always CloseResFile at end: IF ref% <> SYSTEM(7) AND ref% <> PEEKW(&H900) THEN CloseResFile ref% END IF  END 



MORE INFORMATION
WARNING: Never use CloseResFile to close the resource fork of a currently running source file, application, or QuickBASIC itself, or else a &quot;Device I/O Error&quot; or System bomb may occur. You should only use CloseResFile on external resource files (that were opened with OpenResFile).

For an example of how an interpreted program can use SYSTEM(7) to get the file reference number of its own resource area, please see the &quot;Icon Example&quot; program (located in the &quot;Demo Resources&quot; folder of the QuickBASIC 1.00 &quot;Examples&quot; disk). When run in the QuickBASIC interpreter, &quot;Icon Example&quot; displays icon resources that are stored in its own resource fork.

When &quot;Icon Example&quot; is compiled, the program automatically looks in the external &quot;Demo Resources&quot; file for the needed resource. (The SYSTEM(4) routine decides if the program is currently being run interpreted or compiled.) If you want, you can use ResEdit or Statement Mover to move the icon resources into the compiled application &quot;Icon Example apl&quot;, and then use SYSTEM(7) in the compiled version instead of OpenResFile.

Additional query words: MQuickB

Keywords: KB36080

-

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

© Microsoft Corporation. All rights reserved.