Share via


GetFileSize

This function retrieves the size, in bytes, of the specified file. A remote application interface (RAPI) version of this function exists, and it is named CeGetFileSize.

DWORD GetFileSize( 
HANDLE hFile, 
LPDWORD lpFileSizeHigh); 

Parameters

  • hFile
    [in] Open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
  • lpFileSizeHigh
    [out] Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.

Return Values

The low-order DWORD of the file size indicates success. If lpFileSizeHigh is non-NULL, the function puts the high-order DWORD of the file size into the variable pointed to by that parameter. If lpFileSizeHigh is NULL, 0xFFFFFFFF indicates failure. To get extended error information, call GetLastError.

If lpFileSizeHigh is non-NULL, 0xFFFFFFFF indicates failure and GetLastError returns a value other than NO_ERROR.

Remarks

Note that if the return value is 0xFFFFFFFF and lpFileSizeHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following sample code illustrates this point:

// 
// Case One: calling the function with 
//           lpFileSizeHigh == NULL 
 
// Try to obtain hFile's size 
dwSize = GetFileSize (hFile, NULL) ; 
 
// If we failed ... 
if (dwSize == 0xFFFFFFFF) { 
 
    // Obtain the error code. 
    dwError = GetLastError() ; 
 
    // Deal with that failure. 
    . 
    . 
    . 
 
    } // End of error handler 
 
 
// 
// Case Two: calling the function with 
//           lpFileSizeHigh != NULL 
 
// Try to obtain hFile's huge size. 
dwSizeLow = GetFileSize (hFile, & dwSizeHigh) ; 
 
// If we failed ... 
if (dwSizeLow == 0xFFFFFFFF 
    && 
    (dwError = GetLastError()) != NO_ERROR ){ 
 
    // Deal with that failure. 
    . 
    . 
    . 
 
    } // End of error handler. 

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winbase.h   Coredll.lib

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

CeGetFileSize, GetLastError

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.