Download EaseFilter Monitor, Control and Encryption Filter Driver SDK Setup File Download EaseFilter Monitor, Control and Encryption Filter Driver SDK Zip File
Retrieves the size of the specified file, in bytes.
Syntax
DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh );
hFile
A handle to the file.
lpFileSizeHigh
A pointer to the variable where the high-order doubleword of the file size is returned. This parameter can be NULL if the application does not require the high-order doubleword.
If the function succeeds, the return value is the low-order doubleword of the file size, and, iflpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter.
If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call GetLastError. When lpFileSizeHigh is NULL, the results returned for large files are ambiguous, and you will not be able to determine the actual size of the file. It is recommended that you use GetFileSizeEx instead.
If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE andGetLastError will return a value other than NO_ERROR.
You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device. To determine the file type for hFile, use the GetFileType function.
The GetFileSize function retrieves the uncompressed size of a file. Use the GetCompressedFileSizefunction to obtain the compressed size of a file.
Note that if the return value is INVALID_FILE_SIZE (0xffffffff), an application must call GetLastError to determine whether the function has succeeded or failed. The reason the function may appear to fail when it has not is that lpFileSizeHigh could be non-NULL or the file size could be 0xffffffff. In this case, GetLastError will return NO_ERROR (0) upon success. Because of this behavior, it is recommended that you use GetFileSizeEx instead.
Transacted Operations: If there is a transaction bound to the file handle, then the function returns information for the isolated file view.
The following C++ example shows how to use GetFileSize function.
C++ |
---|
//... HANDLE hFile = CreateFile( TEXT("tempfile"), GENERIC_READ | GENERIC_WRITE | DELETE, 0 /* exclusive access */, NULL, CREATE_ALWAYS, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD lowFileSize = 0; DWORD highFileSize = 0; lowFileSize = GetFileSize( hFile, &highFileSize); if (lowFileSize == INVALID_FILE_SIZE && NULL ==highFileSize) { _tprintf( TEXT("error %lu: GetFileSize failed.\n"), GetLastError() ); } else { //get the file size here. } CloseHandle(hFile); // At this point, the file is closed. } else { _tprintf( TEXT("error %lu: could not create tempfile\n"), GetLastError() ); } //... |