January 19th, 2005

CreateProcess does not wait for the process to start

The 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.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.