Microsoft KB Archive/31509

= Opening More than 15 Files in MS-DOS Version 3.3 and Later =

Article ID: 31509

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q31509



SUMMARY
To open more than 15 files at once in a Microsoft MS-DOS-based program, you must do the following:

 Use MS-DOS version 3.3 or later. (You can determine the MS-DOS version number with the VER command at the command prompt.) Add the statement FILES=n to the CONFIG.SYS file. Call MS-DOS Interrupt 21 hex with function 67 hex from the program, as shown in the example listed below. If you are using the SHARE.EXE utility, you must also invoke SHARE/F:nnnnn to increase the area for file-sharing information above the default of 2048 bytes. See your MS-DOS manual for more information about the SHARE utility.

The following is an example of using SHARE/F:

share/f:16384



This information is also included with the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0.



MORE INFORMATION
This technique will retain the file handle table size across a CHAIN for programs compiled without the BC /O option. Programs that are compiled with the BC /O (stand-alone .EXE) option and CHAINed will revert to the original file handle table size.

Notes to Keep in Mind

 * Even if you follow the above steps and specify FILES=255 in the MS-DOS CONFIG.SYS file, you may not be able to access that many files at once in your program because there may not be enough memory available inside the DGROUP data segment to allocate file buffers.
 * Five file handles are taken up by the MS-DOS standard input/output devices.


 * There are memory allocations being done in both the near heap and the far heap. Applications may run out of memory in the far heap before they run out on the near heap. If you are doing sequential file access and use the Len option with a small value when you open the file, you can reduce the amount of memory allocated for the I/O buffer on the far heap.

You can also use the Basic SETMEM function to reduce the size of memory available to Basic as it loads. This method provides more memory to the operating system, which may be necessary to open more than 15 files at the same time. If the interrupt call fails with the return code of 8 (in OUTREGS.AX), indicating insufficient memory, use the SETMEM function to force Basic to release some memory to MS-DOS to make more memory available for file handles.

You almost always need to use the SETMEM function if you are calling this interrupt in an MS-DOS session running in Microsoft Windows (the call to the interrupt returns with the carry flag set and AX = 8, indicating insufficient memory). In addition to using SETMEM to run this program under Microsoft Windows, you must also add/increase &quot;perVMFILES=n&quot;, where n is 0 to 255 (default 10) in the [386enh] section of the Windows SYSTEM.INI file. This entry specifies the number of private file handles that Windows should allocate to each virtual machine. For this entry to take effect, you must NOT use the SHARE.EXE utility. If Share is installed, this setting is ignored.

To call the &quot;set handle count&quot; interrupt, load 67 hex into the AX register, and load the number of desired handles in the BX register. Under MS-DOS version 3.3, you must use an odd number ranging from 21 to 255 for the number of desired handles, because even numbers may make the interrupt fail. This problem was corrected in MS-DOS version 3.30a. Even or odd numbers can be used for the number of desired handles when using Interrupt 67h in MS-DOS version 3.30a.

The following is a Basic code example that uses an MS-DOS interrupt to access more than 20 MS-DOS file handles: ' To run this program in the environment, you must invoke the ' environment with the /L switch to load the default Quick library: '   VBDOS.EXE /L          for Visual Basic 1.0 for MS-DOS

' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program.

' Use the following include file for Visual Basic 1.0 for MS-DOS: REM $INCLUDE: 'VBDOS.BI'

' Use the following include file for QuickBasic: REM $INCLUDE: 'QB.BI'

DIM InRegs AS RegType, OutRegs AS RegType y = SETMEM(-16384)  ' Must usually SETMEM in MS-DOS session under ' Windows

InRegs.ax = &H6700        'SetFileHandles function ' Value in BX register must be odd in MS-DOS version 3.3; odd or even ' in later MS-DOS versions; ranging from 21 to 255: x = 30 InRegs.bx = x             'x is the number of files to open CALL INTERRUPT(&H21, InRegs, OutRegs)

FOR I% = 1 TO x - 5 'five file handles are reserved for MS-DOS ' standard I/O. File$ = &quot;Junk&quot; + STR$(I%) OPEN File$ FOR OUTPUT AS I% PRINT I% NEXT END

Additional query words: VBmsdos QuickBas BasicCom 3.30 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB31509

-

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

© Microsoft Corporation. All rights reserved.