You are currently offline, waiting for your internet to reconnect

Windows File I/O vs. C Run-time File I/O

This article was previously published under Q11988
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
The following functions are provided by the Microsoft C Run-time Library(CRT) and the Windows API to create a file:
   Return Type    API or Function   Category   --------------------------------------------   HFILE          OpenFile          Windows API   HFILE          _lopen/_lcreat    Windows API   int            _open/_creat      CRT   FILE *         fopen             CRT				
These return types (HFILE, int, and FILE *) are not compatible, so they cannot be used in a function which is expecting the other type. The HFILEs arehandles to operating system files (MS-DOS file handles), the ints are CRTfile handles, and the FILE *s are pointers to structures which represent aCRT stream.

For files opened with OpenFile(), _lopen, and _lcreat, the common filemanipuluation routines that you should use are:
For files opened with _open() and _creat(), the common file manipulationroutines that you should use are:
For files opened with fopen, the common file manipulation routines that youshould use are:
For other input and output functions, please check the documentation forinformation on whether they are intended for use with MS-DOS handles(HFILE), streams (FILE *), or low-level I/O (int).
An application should use the OpenFile() API any time an MS-DOS file handleis required.

The open functions do not necessarily open a file in binary raw mode; theapplication is required to set the binary attribute explicitly. TheOpenFile() function automatically performs this step.

If the filename parameter specifies only a filename and extension, the openfunctions search for a matching file only in the current directory.

In Windows, the OpenFile() API creates an MS-DOS file handle through whichan application can access Windows-specific files. OpenFile() initiallyopens the file in binary raw mode by performing an MS-DOS Interrupt 21hFunction 3Dh. If the lpFileName parameter specifies only a filename and anextension, OpenFile() searches for a matching file in the followingdirectories:

  • The current directory.
  • The Windows directory. The GetWindowsDirectory() API returns the path to this directory.
  • The Windows system directory . The GetSystemDirectory() API returns the path to this directory.
  • The directories listed in the PATH environment variable.
3.00 3.10

Article ID: 11988 - Last Review: 10/30/2003 16:37:02 - Revision: 3.0

  • Microsoft Windows Software Development Kit 3.0
  • Microsoft Windows Software Development Kit 3.1
  • kb16bitonly KB11988