FlushFileBuffers

 

Description

Flushes the buffers of a specified file and causes all buffered data to be written to a file.

Syntax

BOOL FlushFileBuffers( HANDLE hFile )

Parameters

hFile
[input] A handle to the open file.

Return

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError.

The function fails if hFile is a handle to the console output. That is because the console output is not buffered. The function returns FALSE, and GetLastError returns ERROR_INVALID_HANDLE.

Examples

Remark

Typically the WriteFile and WriteFileEx functions write data to an internal buffer that the operating system writes to a disk on a regular basis. The FlushFileBuffers function writes to a disk all the buffered information for a specified file.

To open a file for unbuffered I/O, call the CreateFile function with the FILE_FLAG_NO_BUFFERING flag. This prevents the file contents from being cached. However, the file metadata may still be cached. To flush the metadata to a disk, use FlushFileBuffers.

See Also

header to Include

origin.h

Reference