CFile64

$Revision: 17 $

Description

This class gives you the ability to read very large files (up to 18 million terabytes). It is designed to be a drop in replacement for MFC's CFile class.
WARNING! - I've spent too much time writing crappy exception handling code to deal with weird situations that I had disabled the MFC compatibility mode in MFC builds. CFile64 will never throw an exception. If you want MFC exceptions, you will have to write your own file class that inherits from CFile64 and sets the protected member variable m_BeStupidAndUseExceptions to non-false.

Constructors

CFile64()
CFile64( int file_handle );
CFile64( LPCTSTR filename, UINT open_flags );
Constructs this object.

Methods

void Abort( void )
Closes the file. It will not throw any exceptions.
void Close( void )
This closes the file. Like CFile, it will throw a CFileException if there is a problem.
void Dump( CDumpContext& dump_context ) const
Will dump the contents of this object in human readable form. It is present only in debug builds of the class.
CFile64 * Duplicate( void ) const
Will duplicate the handle to the file and return a new CFile64 object to you. Like CFile, it will throw a CFileException if there is a problem.
void Flush( void )
Flushes the data to the disk. Like CFile, it will throw a CFileException if there is a problem.
DWORD GetAttributes( void ) const
Retrieves the attributes used in the wrapped CreateFile() API. This value is used in the sixth parameter to CreateFile(). This method is called by the Open method. The default value is FILE_ATTRIBUTE_NORMAL.
CString GetFileName( void ) const
Returns the name of the file that is open.
CString GetFilePath( void ) const
Returns the complete path of the file that is open.
CString GetFileTitle( void ) const
Returns the title of the file. This is usually the filename without the path or extension.
BOOL GetInformation( BY_HANDLE_FILE_INFORMATION& information ) const
Gives you all kinds of neat information about an open file.
ULONGLONG GetLength( void ) const
Returns the length of the file. It will return zero if it fails.
ULONGLONG GetPosition( void ) const
Returns the current position in the file of the file pointer. Like CFile, it will throw a CFileException if there is a problem.
SECURITY_ATTRIBUTES * GetSecurityAttributes( void ) const
Returns the pointer to the security attributes for this file.
SECURITY_DESCRIPTOR * GetSecurityDescriptor( void ) const
Returns the pointer to the security descriptor for this file.
BOOL GetStatus( CFileStatus& status ) const
static BOOL PASCAL GetStatus)( LPCTSTR filename, CFileStatus& status )
Will fill status with information about the file.
HANDLE GetTemplateFile( void ) const
Retrieves the handle to the file that will be used as a template in the Open method. This handle is used as the seventh parameter to the wrapped CreateFile() API.
void LockRange( ULONGLONG position, ULONGLONG number_of_bytes_to_lock )
Locks the range of bytes in the file. Like CFile, it will throw a CFileException if there is a problem.
BOOL Open( LPCTSTR filename, UINT open_flags, CFileException * exception_p = NULL )
Opens the file. Read CFile's documentation for the open_flags documentation.
DWORD Read( void * buffer, DWORD number_of_bytes_to_read )
DWORD Read( CByteArray& buffer, DWORD number_of_bytes_to_read )
Reads data from the file. It will return the number of bytes read. Like CFile, it will throw a CFileException if there is a problem.
DWORD ReadHuge( void * buffer, DWORD number_of_bytes_to_read )
Simpy calls Read().
static void PASCAL Rename( LPCTSTR old_name, LPCTSTR new_name )
Renames a file. Like CFile, it will throw a CFileException if there is a problem.
static void PASCAL Remove( LPCTSTR old_name, LPCTSTR new_name )
Renames a file. Like CFile, it will throw a CFileException if there is a problem.
ULONGLONG Seek( ULONGLONG offset, UINT from )
Seeks to a position in a file. Like CFile, it will throw a CFileException if there is a problem.
void SeekToBegin( void )
Seeks to the beginning of the file.
ULONGLONG SeekToEnd( void )
Seeks to the end of the file.
void SetAttributes( DWORD attributes )
Sets the attributes used in the wrapped CreateFile() API. This value is used in the sixth parameter to CreateFile().
BOOL SetEndOfFile( ULONGLONG length )
Sets the end of the file at the specified location.
void SetFilePath( LPCTSTR new_name )
Sets the file name.
void SetLength( ULONGLONG new_length )
Sets the end of the file at the specified location. Like CFile, it will throw a CFileException if there is a problem.
static void PASCAL SetStatus( LPCTSTR filename, const CFileStatus& status )
Basically calls CFile's implementation of this function.
void SetTemplateFile( HANDLE template_file_handle )
Sets the handle to the file that will be used as a template in the Open method. This handle is used as the seventh parameter to the wrapped CreateFile() API.
void UnlockRange( ULONGLONG position, ULONGLONG number_of_bytes_to_lock )
Unlocks a range of bytes in a file. Like CFile, it will throw a CFileException if there is a problem.
void Write( const void * buffer, DWORD number_of_bytes )
Writes the bytes to the file. Like CFile, it will throw a CFileException if there is a problem.
void WriteHuge( const void * buffer, DWORD number_of_bytes )
Writes the bytes to the file.

Example

#include <wfc.h>

int _tmain( int number_of_command_line_arguments, LPCTSTR command_line_arguments[] )
{
   WFCTRACEINIT( TEXT( "_tmain()" ) );

   CFile64 file;

   if ( file.Open( command_line_arguments[ 1 ], CFile64::modeRead ) == FALSE )
   {
      return( EXIT_FAILURE );
   }

   file.SetLength( _ttoi64( command_line_arguments[ 2 ] ) );

   file.Close();

   return( EXIT_SUCCESS );
}

API's Used


Samuel R. Blackburn
$Workfile: CFile64.cpp $
$Modtime: 6/26/01 10:46a $