PDA

View Full Version : HideAppAndWait question ...



peterbi
06-25-2004, 01:25 PM
Hi,

I know there are some people there using HideAppAndWait() in ISScript. I am using the pretty original one (code pasted below):
--------------------------------------------------------------------------------
function HideAppAndWait(szCommand, szParameters, nWait)
STARTUPINFO siData;
PROCESS_INFORMATION piData;
NUMBER nExitCode;
begin


siData.cb = 68;
siData.lpReserved = NULL;
siData.lpDesktop = NULL;
siData.lpTitle = NULL;
siData.dwX = 0;
siData.dwY = 0;
siData.dwXSize = 0;
siData.dwYSize = 0;
siData.dwXCountChars = 0;
siData.dwYCountChars = 0;
siData.dwFillAttribute = 0;
siData.dwFlags = 1;//STARTF_USESHOWWINDOW
siData.wShowWindow = SW_HIDE; // I'm not sure if SW_HIDE = 0 is defined pre IS 5.1
siData.lpReserved2 = NULL;
siData.hStdInput = NULL;
siData.hStdOutput = NULL;
siData.hStdError = NULL;

if (CreateProcessA(NULL, szCommand + " " + szParameters, NULL, NULL,
TRUE, 0, NULL, NULL, &siData, &piData) = 0) then
return (-1);
endif;

if (nWait != WAIT) then
return (0);
endif;

repeat
GetExitCodeProcess(piData.hProcess, &nExitCode);
until (nExitCode != STILL_ACTIVE);

return (nExitCode);
end;
-----------------------------------------------------------------------

My question is: how can I use the return value? I see most people use "<0" as error, but I use it and it failed to catch error.

MS site says GetExitCodeProcess() return zero if failed and nonzero if succeed, I am confused to use "<0" to catch error ...

Can anybody provide a better version for checking errors (I mean to catch CreatProcess() and GetExitCodeProcess() errors)?

Thanks,
Peter