How can I get the return value of a process? Basically I'm ShellExecute()ing a .NET process from a DLL (in C++). The process does its task, but now I want to know whether it succeeded or failed. How to do that in WinAPI or MFC?
Use CreateProcess(). keep the process handle and call GetExitCodeProcess() when the process handle becomes signalled.
Use ShellExecuteEx
instead so you can get a handle to the process which was launched. You should then be able to use GetExitCodeProcess
to obtain the exit code.
(I've left this answer here despite the similar one from MSalters, as I suspect you're using ShellExecute
deliberately to get the shell behaviour instead of explicitly creating the process.)
ShellExecute() in its native is 16-bit call, so it is not intended to give feedback / callback althought you can saerch thread / process / memory adress ( if you locate usable memory space ) and its flags ( if there would be no such a thing as bloody flags, WinAPI (32-bit) would be much simpatic than it is now ). To provide full feedback, you can try extended version or CreateProcess() function with is pure 32-bit function. Unfourtinately I cannot give you any detailed info about flags / Lparameters and other API parameters.
Besides, mainly all executive function/procedures/methods retur booleans, so you always can start with [if..then] statement as return provider.
Opps, while i was writing this, already three answers were made.