5.1.2. Example: Windows Stream File Operations

HFILE OpenFile (LPCSTR lpFileName, LPOFSTRUCT lpReOpenBuff, UINT uStyle);

HANDLE CreateFile (
  LPCTSTR lpFileName,
  DWORD dwDesiredAccess,
  DWORD dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD dwCreationDisposition,
  DWORD dwFlagsAndAttributes,
  HANDLE hTemplateFile);

HANDLE ReOpenFile (HANDLE hOriginalFile, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwFlags);

BOOL CloseHandle (HANDLE hObject);

The OpenFile, CreateFile and CloseHandle operations open and close a file stream. Various combinations of flags can direct the calls to create or truncate the file if needed, other flags tell whether the file is opened for reading, writing, or both, and what sharing is allowed.

The OpenFile operation, currently deprecated, illustrates some less common design features. Given appropriate flags, it can open a dialog box when the requested file does not exist. When the file name does not contain a path, the operation searches system directories.

The ReOpenFile operation can open an already open file with different flags.