Good morning everyone,

I have a little program which I have run with VB from years back that opens
a Shell and runs a program and waits for it to finish before passing control
back to the calling program.  I have been trying to convert this code to
Delphi without success.  I am sure it is not rocket science but I have a
little difficulty making the leap to the concept of pointers...

Anyway here is the code.  I was wondering if anyone could give me a couple
of ideas on how to convert this.

All the Type declarations are already in Windows.pas.

Public Sub Shell(PathName As String, Optional WindowStyle As Long)
    
    Dim proc As PROCESS_INFORMATION
    Dim Start As STARTUPINFO
    Dim ret As Long
    ' Initialize the STARTUPINFO structure:
    With Start
        .cb = Len(Start)
        If Not IsMissing(WindowStyle) Then
            .dwFlags = STARTF_USESHOWWINDOW
            .wShowWindow = WindowStyle
        End If
    End With
    ' Start the shelled application:
    ret& = CreateProcessA(0&, PathName, 0&, 0&, 1&, _
            HIGH_PRIORITY_CLASS, 0&, 0&, Start, proc)
    ' Wait for the shelled application to finish:
    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    ret& = CloseHandle(proc.hProcess)
End Sub

I have this so far but it gives me 'Winoldap - This program has performed an
illegal operation...'

I am guessing it is something to do with pointers or some such.

procedure RunShell(FileName : string; WindowStyle : Integer);
var
  proc  : PROCESS_INFORMATION;
  Start : STARTUPINFO;
begin
  // Initialize the STARTUPINFO structure:
  with Start do begin
    cb := SizeOf(Start);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowStyle;
  end;

  // Start the shelled application:
  CreateProcessA(nil, PChar(FileName), nil, nil, True, HIGH_PRIORITY_CLASS,
nil, nil, Start, proc);
  // Wait for the shelled application to finish:
  WaitForSingleObject(proc.hProcess, INFINITE);
  CloseHandle(proc.hProcess);

end;

Thanks in advance

Steve

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to