Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute Hangs in Debugger IDE

Status
Not open for further replies.

6volt

Programmer
Jun 4, 2003
74
US
Works great from executable, but hangs in IDE.

I have a couple of programs that use ShellExecute and they all hang in the debugger.

Any suggestions?

Thanks
Tom
 
I have used CreateProcess without any problems in the following routine which I got from somewhere.
Code:
function RunExecutable (const FileName : String; WaitForIt : boolean) :DWORD;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  errMsg: pChar;
begin
  Result := STILL_ACTIVE;
  GetStartupInfo(StartupInfo);
  if CreateProcess(nil, PChar(FileName), nil, nil, IsConsole,
            NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo)then
  begin
    try
      if (not WaitForIt)
      or (WaitForSingleObject(ProcessInfo.hProcess,INFINITE) = WAIT_OBJECT_0) then
        GetExitCodeProcess(ProcessInfo.hProcess, Result);
      finally
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
      end;
  end
  else
  begin
    if FormatMessage (Format_Message_Allocate_Buffer
    or Format_Message_From_System, nil, GetLastError, 0, @errMsg, 0, nil) <> 0 then
    begin
      try
        raise Exception.Create ('CreateProcess failed with error "' + String (errMsg) + '".');
      finally
        LocalFree (Cardinal (errMsg));
      end;
    end;
  end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top