GetFileSize ()
From ISXKB
(Difference between revisions)
Markus (Talk | contribs)
(New page: This article shows how to use the Windows API function GetFileSize with Inno Setup. This example ignores the high part of the file size. == Declaration == The following declaration is req...)
Newer edit →
Revision as of 09:37, 3 September 2009
This article shows how to use the Windows API function GetFileSize with Inno Setup. This example ignores the high part of the file size.
Contents |
Declaration
The following declaration is required in a [Code] section:
function GetFileSize (hFile: THandle; var lpFileSizeHigh: Integer): Integer; external 'GetFileSize@kernel32.dll stdcall';
This declaration works with files up to 2 GB.
GetFileSize () at MSDN
Examples
This is an example on how to implement a function GetTheFileSize () which opens a file, retrieves its low 32 bit part of the file size as an integer, and closes the file again.
[Code] function GetFileSize (hFile: THandle; var lpFileSizeHigh: Integer): Integer; external 'GetFileSize@kernel32.dll stdcall'; function GetTheFileSize (FileName: String): Integer; var hFile: THandle; iSize: Integer; hSize: Integer; begin hFile := CreateFile (FileName, GENERIC_READ,// Desired access. FILE_SHARE_READ + FILE_SHARE_WRITE, 0, // Security attributes. OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, 0); if (INVALID_HANDLE_VALUE = hFile) then begin Result := 0; Exit; end; iSize := GetFileSize (hFile, hSize); CloseHandle (hFile); Result := iSize; end;