Questions & Answers

CreateProcess() works differently for Debug/Release builds

I am using CreateProcess(), as shown in documentation, to run an app (in x86). Debug build behaves properly. User interacts with app until app exits. Release build makes a blink, the app is loaded and immediately exits, without user interaction.

In both cases (debug/release), WaitForSingleObject() returns WAIT_OBJECT_0.

App one is a console app, prints a few things then waits until user enters a char and exits.

App two is GUI. User does what he wants until he closes the app, and exits.

I am using Visual Studio 2022, C++. Also, I turned off all optimizations for Release, but no change in behavior. Is there some setting in Properties related to CreateProcess()?

Can someone shed some light on this, please. How do I get around it?

2023-01-18 00:00:06
The Win32 APIs do not change based on optimization settings in your program. You have a bug somewhere in your code, please post a self contained minimal reproduction of your source.
2023-01-18 00:00:06
"the app is loaded and immediately exits" with what exit code?
2023-01-18 00:00:06
Check event log to see if an exception crashing that application has been logged. Run it in a debugger (not the parent application calling CreateProcess, but the child process). A "debug" build is much nicer to work with in a debugger, but you'll still get useful information from a "release" build, particularly a "optimizations enabled and debug symbols also generated" type of release.
2023-01-18 00:00:06
@joshpoley : It works in Debug, exact same code. The question is about the pattern using CreateProcess(), which is in documentation of Windows. OK, I will put back all optimizations back. I am not using UNICODE, if that helps.
2023-01-18 00:00:06
Mathias: WaitForSingleObject() shows WAIT_OBJECT_0. I will try to get the exit code of the app, if that is different.
2023-01-18 00:00:06
Ben: How do I check for exception, the event log?
2023-01-18 00:00:06
The exit code for the app launched by CreateProcess() is 0 in Debug mode, and 10 in Release mode. So, the app is crashing, but not because of a bug. I am trying to resolve this code 10 (incorrect environment), so far no luck. I guess it will take time. Any suggestion would be helpful. Thanks for the comments, they help realize where the problem was.
Answers(0) :