Increasing the File Handle Limit with SetHandleCount

Last reviewed: February 15, 1996
Article ID: Q66640
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

Windows-based applications can access more than 20 files. To do this, call the SetHandleCount() function with the number of files needed for the application. The return value from this function specifies the exact number of handles that the application can use. Note that the maximum number of handles that can be requested is 255, and what is returned can be a number less than requested.

MORE INFORMATION

Every Windows-based application is given enough memory when it is loaded to access 20 file handles. This default setting is the same as the setting used in the C run-time libraries. Similarly, the first 5 handles are reserved for basic file I/O, as with any other MS-DOS-based application, leaving the other 15 available for the Windows-based application to use.

When you call SetHandleCount(), the file handle location in the application's program segment prefix (PSP) is expanded to reflect the number of files requested. Because the PSP is unique for every instance of every application, the change in the file handle count will be internal to the application that called SetHandleCount(). No other changes are made in the system. Furthermore, the number of files that may be opened by this application, set by SetHandleCount(), is not limited by the FILES environment variable, declared in the CONFIG.SYS file.

To use these handles, you must also use the Windows file I/O routines (_lopen(), _lclose(), _lread(), and so forth). These routines are versions of the C run-time routines modified to accept a handle value greater than 20. If the Windows file I/O functions do not offer enough flexibility, routines must be written by the ISV with the appropriate functionality using Int 21H calls. If Int 21H calls are to be used, we recommend that these calls be performed in a dynamic-link library (DLL). Doing this will make it easier to service the code in the future if significant changes are made with the Windows file I/O routines.

If you want to use the C run-time functions instead of using the Windows file I/O routines or writing each routine separately, you must modify the C run-time code to increase the file handle limit. For more information on increasing the file limit, query in the C language Knowledge Base or consult the documentation supplied with the Microsoft C Compiler. Once the C run-time code has been modified, the C run-time routines can be used within the limit of file handles set during the modification. A modified C run-time routine will fail if it is passed a file handle value greater than the new limit that was set.

The above approaches are the only acceptable methods of using more than the default 20 file handles in a Windows-based application. If you attempt to increase the number of files by calling Int 21H, Function 67H, important information will not be recorded in Windows and you will experience problems using file handles over the default number.

There is a sample application named HANDLCNT in the Microsoft Software Library that demonstrates the use of SetHandleCount().

Download HANDLCNT.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download HANDLCNT.EXE (size: 24627 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get HANDLCNT.EXE (size: 24627 bytes) 
    


Additional reference words: softlib HANDLCNT.EXE
KBCategory: kbprg kbfile
KBSubcategory: GenSDK


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.