With the popularity of Windows 2000 and XP, there are now more and more, and the CFILE class of the MFC in VC6 supports only 4GB files, because 32-bit integers in the CFILE class to process files, 32-bit The number of numbers is 2 32 (4GB), more than this range of file cfile can't manage, Microsoft's CFILE CFILE class supports greater than 4GB files, and .NET is not popular, developing desktop app VC6 or preferred So we can write a CFILE inheritance class CFILE64 with VC7, so that it supports a file greater than 4GB: Class CFile64: Public cfile {public:
// attributes ulonglong getPosition ();
// Overridables
Virtual Ulonglong Seek (Longlong Loff, Uint NFROM); Virtual Void SetLENGTH (Ulonglong GetLength ();
Virtual Void Lockrange (Ulonglong DWPOS, ULONGLONG DWCOUNT); Virtual Void Unlockrange (Ulonglong dwpos);
}
#include "stdafx.h" #include "file64.h"
// cfile64 implemethation
Ulonglong cfile64 :: Seek (longlong loff, uint nfrom) {assert_valid (this); assert (Handle) m_hfile! = INVALID_HANDLE_VALUE); assert (nfrom == begin || nfrom == end || nfrom == current); askERT (begin == file_begin && end_end && current == file_current);
Large_integer lioff;
Lioff.quadpart = Loff; Lioff.lowPart = :: setFilepointer ((handle) m_hfile, lioff.lowpart, & lioff.highpart, (dword) nfrom); if (lioff.lowpart == (dword) -1) if (:: GetLastError ()! = No_error) cfileException :: throwoserror ((long) :: getLastError (), m_strfilename);
Return Lioff.quadpart;
Ulonglong cfile64 :: getposition () {assert_valid (this); assert ((handle) m_hfile! = Invalid_handle_value);
LIARGE_INTEGER LIPOS; lipos.quadpart = 0; lipos.lowpart = :: setFilepointer ((handle) m_hfile, lipos.lowpart, & lipos.highpart, file_current); if (lipos.lowpart == (dword) -1) IF (:: GetLastError ()! = No_error) cfileException :: throwoserror ((long) :: getLastError (), m_strfilename); return lipos.quadpart;}
Void cfile64 :: Lockrange (Ulonglong dwpos, ulonglong dwcount) {assert_valid (this); assert ((handle) m_hfile! = invalid_handle_value);
Ularge_integer lipos; ularge_integer licount;
liPos.QuadPart = dwPos; liCount.QuadPart = dwCount; (! :: LockFile ((HANDLE) m_hFile, liPos.LowPart, liPos.HighPart, liCount.LowPart, liCount.HighPart)) if {CFileException :: ThrowOsError ((LONG) :: getLastError (), m_strfilename);}}
Void cfile64 :: unlockrange (ulonglong dwpos, ulonglong dwcount) {assert_valid (this); assert ((handle) m_hfile! = invalid_handle_value);
Ularge_integer lipos; ularge_integer licount;
liPos.QuadPart = dwPos; liCount.QuadPart = dwCount; (! :: UnlockFile ((HANDLE) m_hFile, liPos.LowPart, liPos.HighPart, liCount.LowPart, liCount.HighPart)) if {CFileException :: ThrowOsError ((LONG) :: getLastError (), m_strfilename);}}
Void cfile64 :: setlength (ulonglong dwnewlen) {assert_valid (this); assert ((handle) m_hfile! = INVALID_HANDLE_VALUE);
Seek (dwnewlen, (uint) begin;
IF (! :: setendoffile) cfileException :: throwoserror ((long) :: getLastError (), m_strfilename);}
Ulonglong cfile64 :: getLENGTH () {assert_valid (this);
Ularge_integer lisize; lisize.lowpart = :: getFileSize ((Handle) M_HFile, & Lisize.highpart; if (Lisize.lowPart == (DWORD) -1) IF (: getLastError ()! = No_ERROR) CFILEXCEPTION:: Throwoserror (Long) :: getLastError (), m_strfilename); returnis.quadpart;}
/
Longlong is a 64-bit integer, so that the most supportable maximum file is 18000000000GB, you can also overload other functions of CFILE according to your own needs.