GetFileSize ()

From ISXKB

(Difference between revisions)
Jump to: navigation, search
(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...)
Current revision (09:37, 3 September 2009) (view source)
m (Too stupid to spell CloseHandle properly)
 
Line 46: Line 46:
== See Also ==
== See Also ==
*[[CreateFile ()]]
*[[CreateFile ()]]
-
*[[ClosHandle ()]]
+
*[[CloseHandle ()]]
*[[ReadFile ()]]
*[[ReadFile ()]]
*[[WriteFile ()]]
*[[WriteFile ()]]
[[Category:Windows API function calls with Inno Setup]]
[[Category:Windows API function calls with Inno Setup]]

Current revision

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;

See Also

Personal tools
Ads: