Search code examples
c++-cliexit-code

Retrieving exit code in ProcessExit handler?


I'm writing a little C++/CLI application that calls a lot of libraries. Inside some of them there is at least one exit(xyz) and I catch it by handling AppDomain.ProcessExit(). Works fine. Since the call to exit(...) has already been done, I would like to retrieve the exit code passed to this function.

My problem is that it seems that the exit code is not available before the complete exit of the process and, of course, in my handler, the process is not "completely" terminated/exited. For example, I tried:

int ec = System::Diagnostics::Process:GetCurrentProcess()->ExitCode;

But I got an exception. Also it seems that the API Win32 GetExitCodeProcess() will return me a STILL_ACTIVE error??? I hope this value is registered/accessible somewhere?

Any idea? I'm running on Win 7 and Win 10. Thanks in advance for your help.


Solution

  • System::Environment::ExitCode;
    

    Process, AppDomain, Environment... I missed this one! I hope my question/answer will help someone some day!