Code snippet ...
|
{$IFDEF VER100}
{TImageDosHeader isn't defined in Delphi 3 so here's an
an abbreviated structure definition...}
type
PImageDosHeader = ^TImageDosHeader;
TImageDosHeader = packed record
e_magic : WORD;
e_ignore : packed array [0..28] of WORD;
_lfanew : Longint;
end;
{$ENDIF}
function GetExeSize: cardinal;
var
p: pchar;
i, NumSections: integer;
begin
result := 0; // if error then result = 0
p := pointer(hinstance);
inc(p, PImageDosHeader(p)._lfanew + sizeof(dword));
NumSections := PImageFileHeader(p).NumberOfSections;
inc(p,sizeof(TImageFileHeader)+ sizeof(TImageOptionalHeader));
for i := 1 to NumSections do
begin
with PImageSectionHeader(p)^ do
if PointerToRawData+SizeOfRawData > result then
result := PointerToRawData+SizeOfRawData;
inc(p, sizeof(TImageSectionHeader));
end;
end;
|
|
|
|