Loading a File
Read a few bytes of data from the running .EXE
procedure TForm1.Button1Click(Sender: TObject);
var
  F: THandle;
  D: Pointer;
  W: DWord;
begin
  F := CreateFile(PChar(Application.EXEname), GENRIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, Open_Existing, 0, 0);
  if F = INVALID_HANDLE_VALUE then
    Exit;

  GetMem(D, 1000);
  if ReadFile(F, D^, 1000, @W, nil) then
    ShowMessage('Success: ' + IntToStr(W) + ' bytes read');
  FreeMem(D, 1000);
  CloseHandle(F);
end;
Notes:
Use GetFileSize() to determine how much memory to allocate is you want to grab the entire file.
You could add a custom data segment to your Exe... this will reduce the chance of a virus scanner clipping it accidentally thinking it's a trojan.
Home