01-26-2011 02:39 PM
CreateProcess() returns 0 executing this code:
ZeroMemory(&si,sizeof si);
si.cb=sizeof si;
result=CreateProcess(NULL,szCommand,NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|DETACHED_PROCESS,
NULL,NULL,&si,&piProcess);
if (result==TRUE){
CloseHandle(piProcess.hThread);
if (WaitForSingleObject(piProcess.hProcess,INFINITE)!=WAIT_FAILED)
GetExitCodeProcess(piProcess.hProcess,&dwExitCode);
CloseHandle(piProcess.hProcess);
exitCode = dwExitCode;
}
Solved! Go to Solution.
01-26-2011 03:15 PM
I found a problem but ran into another. GetExitCodeProcess() returns exit code but not the return value. How can I get return value?
01-27-2011 11:36 AM
dtadenev,
What do you mean when you say your are not getting a return value? Is the function returning NULL? Is your command setup like:
result = GetExitCodeProcess(param1, param2);
result in this example should be a boolean value. Here is the documentation for the function. GetExitCodeProcess
01-27-2011 11:41 AM
I mean the value returned by main function of processing exe
01-27-2011 05:00 PM
The exit code is the return value. The documentation describes the following:
This function returns immediately. If the process has not terminated and the function succeeds, the status returned is STILL_ACTIVE. If the process has terminated and the function succeeds, the status returned is one of the following values:
Important The GetExitCodeProcess function returns a valid error code defined by the application only after the thread terminates. Therefore, an application should not use STILL_ACTIVE (259) as an error code. If a thread returns STILL_ACTIVE (259) as an error code, applications that test for this value could interpret it to mean that the thread is still running and continue to test for the completion of the thread after the thread has terminated, which could put the application into an infinite loop.
From what I understand, this will return the value returned by main unless the process is still running, in which case it will return 259.
01-27-2011 05:29 PM
I am looking to catch return value of executable which should be array of characters. Are there any possibilities to do that?
01-28-2011 11:47 AM
I think the only return types allowed for main are int and void. Therefore it is not possible to return a char array or even a pointer to one. Instead there are two approaches to choose from depending on your application.
1. Change main to a regular function and call it from the other application. If you want it to be compiled code and not in your project, then make it into a DLL.
2. Use dup to redirect stdout to be an input to your application. This is like piping if you have used console applications much. A google search should return a lot of information on this.