In my SATA Controller Identification tool I was using the TSaveDialog (Delphi 2010) but I got a report that under Windows PE the dialog is never shown.

There’s no exception and I didn’t really bother to check why it fails. Instead I decided to replace it with the GetSaveFileName API which does work under Windows PE.

Example:

objectpascal Download
var
  sl: TStringList;
  ofn: OPENFILENAME;
  Buf: array[0..MAX_PATH] of Char;

  ZeroMemory(@ofn, SizeOf(ofn));
  ofn.lStructSize := SizeOf(ofn);
  ofn.hWndOwner := Form1.Handle;
  ofn.lpstrFile := @Buf[0];
  ofn.nMaxFile := Length(Buf);
  ofn.lpstrInitialDir := PChar(GetCurrentDir);
  ofn.lpstrFilter := 'Any File'#0'*.*'#0'Registry file'#0'*.reg'#0#0;
  ofn.nFilterIndex := 0;
  ZeroMemory(@Buf, SizeOf(Buf));
  if GetSaveFileName(ofn) then
  begin
    // Buf now contains the filename
  end;