11
votes

I have a Delphi console application that at the end needs to launch one of two applications.

I'm having some problems getting ShellExecute to work without erroring, and I think the problem is associated with not having a handle for the console applicaiton.

The line that is causing me grief is:

ShellExecute(0, 'open', 'someapplication.exe', nil, nil, SW_SHOWNORMAL);

I think that the 0 in the handle is the problem as it compiles OK and runs in the debugger OK, but if I try to run the executable I get an unhandled error (the console application thinks that it has finished happily).

1
I think you need to disable "Debug Spawned Processes" in IDE, press F6 and type "debug spawned processes", if that's checked, uncheck it and try againuser497849
HWND(0) is HWND_DESKTOP, for your information.OnTheFly

1 Answers

12
votes

Passing 0 for the hwnd parameter is fine. The documentation describes the parameter thus:

A handle to the parent window used for displaying a UI or error messages. This value can be NULL if the operation is not associated with a window.

Your error is due to something else.