LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CreateProcess() returns 0

Solved!
Go to solution

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;
   }

0 Kudos
Message 1 of 7
(7,837 Views)

I found a problem but ran into another. GetExitCodeProcess() returns exit code but not the return value. How can I get return value?

0 Kudos
Message 2 of 7
(7,830 Views)

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

National Instruments
0 Kudos
Message 3 of 7
(7,808 Views)

I mean the value returned by main function of processing exe

0 Kudos
Message 4 of 7
(7,806 Views)
Solution
Accepted by topic author dtadenev

The exit code is the return value. The documentation describes the following:

 

 

Remarks

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:

  • The exit value specified in the ExitProcess or TerminateProcess function.
  • The return value from the main or WinMain function of the process.
  • The exception value for an unhandled exception that caused the process to terminate.

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.

National Instruments
0 Kudos
Message 5 of 7
(7,788 Views)

I am looking to catch return value of executable which should be array of characters. Are there any possibilities to do that?

0 Kudos
Message 6 of 7
(7,785 Views)

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.

National Instruments
0 Kudos
Message 7 of 7
(7,757 Views)