Considering the following command-line arguments
"alfa" "beta" "4"
When I specify the Run>Parameters... for an project I'm working the application shows on Process Explorer as command-line:
"c:\myapp\myapp.exe" "alfa" "beta" "4"
And ParamCount shows 4 parameters. But when I start the same executable from an launcher application (which does access control), Process Explorer shows:
"alfa" "beta" "4"
ParamCount show 3 paramers.
The command-line was extracted from the launcher application.
In theory it would work, since when started from launcher the application work flawlessly. When started from IDE it tries to do StrToInt on the "4"
above, but retrieves just the "beta"
parameter instead.
Sample code from launcher application:
var
StartupInfo: TSTARTUPINFO;
ProcessInfo: PROCESS_INFORMATION;
CurrentDirPath: String;
begin
Result := 0;
ZeroMemory(@StartupInfo, SizeOf(StartupInfo));
StartupInfo.cb := SizeOf(StartupInfo);
DirCorrente := ExtractFilePath(sExe);
if CreateProcess(PChar(sExe), PChar(sParam), nil, nil, true,
NORMAL_PRIORITY_CLASS, nil, PChar(CurrentDirPath),
StartupInfo, ProcessInfo) then
The content of sParam is the command-line arguments above and sExe is the executable path. Why this happens?
NOTE:I already devised how to change the command-line arguments interpretation to be robust for this edge case - the point here is WHY this happens.