Microsoft KB Archive/40271

From BetaArchive Wiki

Article ID: 40271

Article Last Modified on 11/21/2006

This article was previously published under Q40271

SYMPTOMS

In the interpreter in QuickBasic for Macintosh, the OpenResFile routine cannot open the resource fork of any Macintosh application [such as Microsoft Word, or a compiled QuickBasic "apl" file (which has a resource type of APPL)]. OpenResFile can open only the resource fork of external nonapplication files (such as QuickBasic's Demo Resources file, a text file, or a Basic source file). This problem doesn't occur for the OpenResFile statement in programs compiled in QuickBasic.

The error "Bad File Mode" (number 54) displays when you attempt to open a Macintosh application with the OpenResFile statement in the interpreter.

Microsoft has confirmed this to be a bug in the OpenResFile MBLC routine in the interpreter in Microsoft QuickBasic Version 1.00 for the Macintosh . We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

To work around this problem in the interpreter, use the ToolBox statement as described below, or use a compiled program.

MORE INFORMATION

If you want to open the resource fork of an external application, you must use the ToolBox statement (which is an MBLC routine in QuickBasic) instead of the OpenResFile statement (another MBLC routine). You need to call ToolBox to invoke the following low-level Macintosh File Manager routine:

   PBOpenRF ROM trap
                

Please see the Statement Mover program for an example. Another brief example is shown at the bottom of this article. Note: Only advanced Macintosh developers familiar with "Inside Macintosh" by Apple Computer (published by Addison-Wesley) should attempt to use the ToolBox statement.

The QuickBasic subprogram OpenFile, located in the Statement Mover source file, demonstrates how to use the ToolBox statement to open the resource fork of an application (or any file). (The Statement Mover program is found in the Tools folder on the QuickBasic release disk.)

For more information about low-level Macintosh File Manager routines (or other ROM traps accessible with the ToolBox routine), please refer to "Inside Macintosh."

More information about Statement Mover can be found starting on Page 99 of the "Microsoft QuickBasic for Macintosh : User's Guide," and on Page 418 of the "Microsoft QuickBasic for Macintosh : Language Reference."

Code Examples

The following code incorrectly produces the "Bad File Mode" error when run in the interpreter in QuickBasic (the "Test Apl" file opened by this program must be an existing external compiled application to duplicate the problem):

   ref% = 0
   OpenResfile "Test Apl", ref%
   PRINT ref%
   END
                

The following is a workaround:

   ref% = 0
   OpenResFileTrap% = &HA997
   toolbox "i"
   toolbox "WQ", OpenResFileTrap%,"Test Apl",ref%
   PRINT ref%   ' At this point you can use ref%, the resource file
   END          ' reference number, to access stored resources.
                

Background Information

Note that compiled programs that need to access their own resource fork must use the SYSTEM(7) function instead of using OpenResFile. However, a compiled program is free to use OpenResfile to open the resource fork of any file or application that is external to the current compiled program.

An interpreted program must use SYSTEM(7), not OpenResFile, to get the file reference number of its own source file. An interpreted program is free to use OpenResFile to open the resource fork of all external files except for application files, where you must use the above ToolBox statement as a workaround.

For more information about the SYSTEM(7) function and the OpenResFile routine, query on the following words:

SYSTEM(7) and OpenResFile



Additional query words: MQuickB

Keywords: kbbug KB40271