Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  The newer interrupt 21H functions in DOS versions 2.0 and later rely on
  the notion of handles. Handles are 16-bit numbers that DOS uses to
  identify open files. Handles can also identify other sources of input and
  output for a program, including the keyboard and the video display.
  (They're also another example of the UNIX influence: In UNIX, file handles
  are called "file descriptors" but are used in essentially the same way as
  they are in DOS.)

  The use of handles allows DOS to be more flexible in its file management
  services than it was with FCB-based file services. In particular,
  capabilities such as file redirection and support for hierarchical
  directories would have been very difficult to graft onto the fixed-format
  FCB data structure. Furthermore, the use of handles actually simplifies
  file management by making the mechanics of file input/output--parsing
  filenames, keeping track of the current file position, and so on--the
  responsibility of DOS instead of your programs.

  DOS assigns a new handle number whenever you create or open a file. Five
  standard handles, numbered 0 through 4, are automatically available to
  every program. (See Figure 17-1.) Other handles, with higher handle
  numbers, are issued by DOS as needed.

  Handle         Use                                         Default Device
  --------------------------------------------------------------------------
  0              Standard input (normally keyboard input)    CON
  1              Standard output (normally screen output)    CON
  2              Standard error output (always to the        CON
                 screen)
  3              Standard auxiliary device (AUX device)      AUX
  4              Standard printer (LPT1 or PRN device)       PRN
  --------------------------------------------------------------------------

  Figure 17-1.  The five standard DOS handles.

  --------------------------------------------------------------------------
  NOTE:
    Of the five standard DOS handles, only the first three are supported in
    OS/2 protected mode. If you are programming with upward compatibility in
    mind, you should avoid using handles 3 and 4 by default. Instead, open
    the serial port and printer devices explicitly, as you would any other
    file or input/output device.
  --------------------------------------------------------------------------

  DOS limits the use of handles in regard to how many files or devices your
  program can open at one time:

  .  DOS maintains an internal data structure that controls I/O for each
     file or other input/output device associated with a handle. The default
     size of this data structure allows for only 8 handles. Fortunately, the
     FILES command in the CONFIG.SYS file lets you increase the number of
     possible handles (99 in DOS versions prior to 3.0; 255 in versions 3.0
     and later).

  .  DOS uses a reserved area in each program's PSP to maintain a table of
     handles associated with the program. This table has room for a maximum
     of 20 handles. Thus, even if you specify FILES = 30 in your CONFIG.SYS
     file, your programs will still be able to use only 20 handles at a
     time. (DOS 3.3 provides a way around this through interrupt 21H,
     function 67H. See page 392 for details.) Fortunately, few applications
     require more than 20 different files to be open at once, so these
     limitations are not usually important.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson