E
E
ErickSkrauch2014-03-27 17:14:22
Java
ErickSkrauch, 2014-03-27 17:14:22

Why doesn't CreateProcess always work correctly?

The code in Delphi looks like this:

FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0);
with StartUpInfo do begin
  cb:= SizeOf(TStartUpInfo);
  dwFlags:= STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  wShowWindow:= ShowCmd;
end;
CreateProcess(nil, PWideChar(JavaPath+' '+Parameters), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, MinecraftPath, StartUpInfo, ProcessInfo);
WaitForInputIdle(hProcess, INFINITE);
WaitforSingleObject(hProcess, INFINITE);
GetExitCodeProcess(hProcess, ExitCode);
CloseHandle(hThread);
CloseHandle(hProcess);

The problem is that when you try to run 1.6.4 and Forge modifications (in fact, just a different set of libraries and the main class), nothing happens - it's not clear where to catch the error.
And we would look for the problem in ourselves, but if we take the code that Delphi executes and insert it tritely into a bat file, everything will work.
What to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2014-03-27
@MaxiMonster

Maybe something like ShellExecute will help you?

A
Alexander Kind, 2014-03-27
@shineblu

Good afternoon,
So everything stops at WaitforSingleObject(hProcess, INFINITE); after you have called the function for the first time. The second application will not start until the first one is completed.
As an addendum, try this function:

function ExecuteApplication(ACmd: string; AWaitForTerminate: boolean=false; AHideWindow: boolean = false): THandle;
var
  si: STARTUPINFO;
  pi: PROCESS_INFORMATION;
begin
  Result:=0;
  try
      ZeroMemory(@si,sizeof(si));
      si.cb:=SizeOf(si);
      si.dwFlags := STARTF_USESHOWWINDOW;
      if AHideWindow then si.wShowWindow := SW_HIDE else si.wShowWindow := SW_SHOW;
      if not CreateProcess(nil, PChar(ACmd), nil, nil, False, 0, nil, nil, si, pi)
      then begin
          Exit;
      end;
      Result:=pi.hProcess;
      if AWaitForTerminate
      then begin
          WaitForSingleObject(pi.hProcess, INFINITE );
          CloseHandle(pi.hProcess);
          CloseHandle(pi.hThread);
      end;
  except
  end;
end;

And for debugging - check what is contained in the ACmd variable. Those. if your path to the EXE and arguments contain spaces, then the path to the application and each such parameter must be enclosed in quotes
. Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question