Originally Posted by
Ducky
I can only get the size of a file of 2GB with ifstream and around 3.5GB with CreateFile().
I tried this old program with a 6GB .avi file captured by fraps, and it returned the proper file size:6,555,552,672 == 0x186bdcba0 bytes. This was run on Windows XP Pro 32 bit. It takes a bit less than 100 seconds to read the entire file (August, 2011 system, Intel 2600K cpu, 4GB ram, three 2 TB hard drives).
Code:
#include <windows.h> /* Win32 API */
#include <stdio.h>
#define BFRSZ 0x40000000ul /* buffer size == 1GB */
static HANDLE hSrc; /* source file params*/
static DWORD dwSrcCnt;
static LARGE_INTEGER liSrcSize;
static LARGE_INTEGER liSrcCnt;
static DWORD dwErr; /* getlasterror params */
static BYTE abErrMsg[128];
static LPVOID lpBfr; /* allocated bufer */
int main (int argc, BYTE *argv[])
{
hSrc = INVALID_HANDLE_VALUE; /* init handle */
hSrc = CreateFile(argv[1], /* open source file */
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
if(hSrc == INVALID_HANDLE_VALUE){
hSrc = 0;
goto exit0;
}
if(0 == GetFileSizeEx(hSrc, &liSrcSize)){
dwErr = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) abErrMsg, sizeof(abErrMsg), NULL );
printf("\n GetFileSizeEx() failed, code %d:%s", dwErr, abErrMsg);
}
printf("%8lx%08lx file size\n", liSrcSize.HighPart, liSrcSize.LowPart);
lpBfr = malloc(BFRSZ); /* allocate buffer */
if(lpBfr == NULL)
goto exit0;
while(1){ /* read file */
ReadFile(hSrc, lpBfr, BFRSZ, &dwSrcCnt, NULL);
if(!dwSrcCnt)
break;
liSrcCnt.QuadPart += dwSrcCnt;
}
printf("%8lx%08lx bytes read\n", liSrcCnt.HighPart, liSrcCnt.LowPart);
exit0:
if(hSrc) /* close file */
CloseHandle(hSrc);
if(lpBfr) /* release mem */
free(lpBfr);
return(0);
}