CreateProcess does not wait for the process to start
CreateProcess function creates a new process, but it doesn’t wait for the process to get off the ground before returning. It just creates the process object and lets it go to do its thing. The Win32 process model is that each process initializes itself in context. When a process object is created, it is practically empty, save for enough information to get the program execution procedure started. When the thread in the process object is scheduled, it starts doing the real work of loading DLLs, initializing them in the correct order, then calling to the program’s entry point. If, along the way, one of these process startup steps fails, the process is killed, and the exit code is the reason why the process couldn’t get started. For example, if the problem was that a function could not be found in a DLL, the exit code will be STATUS_ENTRYPOINT_NOT_FOUND.
(And don’t forget that you can use the
SetErrorMode function to disable the error dialog.)