delphishellexecute

Shellexecute Return Value error messages


I'm getting the return value when I call ShellExecute - an integer. Where can I get the associated error messages? I know they're general, but I've seen messages in the MS documentation.


Solution

  • The error handling for ShellExecute is something of a disaster. Raymond Chen discusses it here: Why does ShellExecute return SE_ERR_ACCESSDENIED for nearly everything? So, even if you can convert the handful of possible ShellExecute errors into text, you'll find that you invariably get Access denied. And that's not very helpful.

    The bottom line is that if you want real error reporting then you need to use ShellExecuteEx. If that fails you call GetLastError to get the Win32 error. To turn it into an exception with the descriptive text, call RaiseLastOSError. If you just want the descriptive text associated with an error, you call SysErrorMessage.