"Invalid Function Call"; OpenResFile Makes Empty File; Path (42462)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0

This article was previously published under Q42462

SUMMARY

When using the OpenResFile statement, you must specify the complete path to the resource file being opened, such as in the following example:
   ref%=0
   OpenResFile "Examples:QB Demos:Demo Resources",ref%
				
Otherwise, you must put the resource file in the current folder (the folder where QuickBASIC itself or the compiled application is located) and specify no path, as follows:
   ref%=0
   OpenResFile "Demo Resources",ref%
				
If the file does not exist in the specified location, then OpenResFile will create an empty file with the specified name. If the file is created empty, it will have no resources, and calling a subsequent library routine that tries to pull a resource out of it may produce a run-time error, such as the following:
"Invalid Function Call"
NOTE: You can use CHDIR to change the current default folder where OpenResFile searches for unqualified filenames, as follows:
   CHDIR "Examples:QB Demos:"
   OpenResFile "Demo Resources"
				

MORE INFORMATION

This subject can be demonstrated by compiling the demonstration program DIALOG EXAMPLE, included with QuickBASIC Version 1.00 in the QB Demos folder. If the file is compiled into an application and put in a different folder, the program will not find the needed resources as it does inside the interpreter. (The interpreted version always finds the resources, which Microsoft stored in the resource fork of the source file itself.)

Here are three methods to make the compiled version of DIALOG EXAMPLE find the DEMO RESOURCES file:
  1. Copy the DEMO RESOURCES file into the same folder as the DIALOG EXAMPLE APL compiled application.
  2. Modify the source code of DIALOG EXAMPLE, changing the following line
          IF SYSTEM(4) THEN   'If compiled...
             OpenResFile "Demo Resources",ref%
    						
    to include the drive and path of the DEMO RESOURCES file, for example:
          IF SYSTEM(4) THEN   'If compiled...
             OpenResFile "HD 20:Folder 1:Demo Resources",ref%
    						
    Note that the SYSTEM(4) function returns a value of "true" (non-zero) when the program is compiled, and "false" (zero) when interpreted.
  3. Modify the source code of DIALOG EXAMPLE and add a CHDIR statement to change the default directory. In the following example, CHDIR changes the default folder to "Folder 1" on the disk named "HD 20":
          IF SYSTEM(4) THEN   'If compiled...
             CHDIR "HD 20:Folder 1:"
             OpenResFile "Demo Resources",ref%

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB42462 kbAudDeveloper