GetFileSizeEx function

Expand
4 out of 12 rated this helpful - Rate this topic

GetFileSizeEx function

Applies to: desktop apps only

Retrieves the size of the specified file.

Syntax

BOOL WINAPI GetFileSizeEx(
  __in   HANDLE hFile,
  __out  PLARGE_INTEGER lpFileSize
);

Parameters

hFile [in]

A handle to the file. The handle must have been created with either the GENERIC_READ or GENERIC_WRITE access right or equivalent. For more information, see File Security and Access Rights.

lpFileSize [out]

A pointer to a LARGE_INTEGER structure that receives the file size, in bytes.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Transacted Operations:  If there is a transaction bound to the file handle, then the function returns information for the isolated file view.
Metro style apps:  GetFileSizeEx is not supported. Use GetFileInformationByHandleEx.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

FileAPI.h (include Windows.h);
WinBase.h on Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

File Management Functions
LARGE_INTEGER

 

 

Send comments about this topic to Microsoft

Build date: 5/5/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
Visual C++ 6 syntax
typedef BOOL (WINAPI *GETFILESIZEEX)(HANDLE, PLARGE_INTEGER);
GETFILESIZEEX GetFileSizeEx;
------------------------------------------------------
 __int64 ReturnData;
 LARGE_INTEGER DataTemp;

 HMODULE TheKernel32 = ::GetModuleHandleW(L"kernel32.dll");
 if(TheKernel32 == NULL)
 {
  TheKernel32 = ::LoadLibraryW(L"kernel32.dll");
 }
 if(TheKernel32 != NULL)
 {
  GetFileSizeEx = (GETFILESIZEEX)::GetProcAddress(TheKernel32, "GetFileSizeEx");
  if(GetFileSizeEx != NULL)
  {
   if(::GetFileSizeEx(FileCode, &DataTemp) != 0) //檢查是否成功取得
   {
    ReturnData = DataTemp.QuadPart;
   }else{
    ReturnData = -1;
   }   
  }else{
   //error
   ReturnData = -1;
  }
  ::FreeLibrary(TheKernel32); //釋放Library
 }
11/17/2010
C# syntax
Int64 should also work:
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern bool GetFileSizeEx(SafeHandle hFile, ref long lpFileSize);
And please always use SafeHandle instead of IntPtr for handles!
8/24/2009
vb.net syntax
<DllImport("kernel32.dll", SetLastError:=True)> 
Public Shared Function GetFileSizeEx(ByVal hFile As IntPtr, ByRef lpFileSize As LARGE_INTEGER) As Boolean End Function
5/4/2009
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern bool GetFileSizeEx(IntPtr hFile, ref LARGE_INTEGER lpFileSize);
5/4/2009