11

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

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Dan Kelly
  • 2,634
  • 5
  • 41
  • 61
  • 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 again –  Feb 24 '12 at 11:20
  • HWND(0) is HWND_DESKTOP, for your information. – OnTheFly Feb 24 '12 at 16:58

1 Answers1

13

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490