_int64 GetFileSize(const char *szFileName)
{
//低位,高位,錯誤代碼
DWord dwSizeLow = 0, dwSizeHigh = 0;
HANDLE hFile = CreateFile(szFileName,GENERIC_READ,FILE_SHARE_READ,
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
MessageBox(NULL,_T("打開文件失敗!"),_T("提示!"),MB_OK|MB_ICONINFORMATION);
return -1;
}
dwSizeLow = ::GetFileSize((HANDLE)hFile, &dwSizeHigh);
if ( (dwSizeLow == 0xFFFFFFFF) && (GetLastError() != NO_ERROR) )
{
MessageBox(NULL,_T("取得文件大小出錯!"),_T("提示!"),MB_OK|MB_ICONINFORMATION);
CloseHandle(hFile);
return -1;
}
_int64 lFileSize = 0, lPow = 0;
lPow = (LONGLONG)pow(2,32);
lFileSize = dwSizeHigh * lPow+dwSizeLow;
CloseHandle(hFile);
return lFileSize;
}