Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Delphi - Using ShellExecute's return value
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2858
Topic starter
November 4, 2013 9:43 AM
If the returncode of ShellExceute <=32 then something went wrong.
If >32 then this is a handle to the application or DDE server that executed the command.
The error can be handled by
showmessage(SysErrorMessage(ReturnValue)+ ' '+ IntToStr(ReturnValue))
Example;
procedure TForm1.Button1Click(Sender: TObject);
var
errorcode: integer;
begin
errorcode := ShellExecute(0, 'open', pchar('c:test.txt'), nil, nil, SW_NORMAL);
case errorcode of
2:showmessage('file not found');
3:showmessage('path not found');
5:showmessage('access denied');
8:showmessage('not enough memory');
32:showmessage('dynamic-link library not found');
26:showmessage('sharing violation');
27:showmessage('filename association incomplete or invalid');
28:showmessage('DDE request timed out');
29:showmessage('DDE transaction failed');
30:showmessage('DDE busy');
31:showmessage('no application associated with the given filename extension');
end;
{
SE_ERR_FNF = 2;
SE_ERR_PNF = 3;
SE_ERR_ACCESSDENIED = 5;
SE_ERR_OOM = 8;
SE_ERR_DLLNOTFOUND = 32;
SE_ERR_SHARE = 26;
SE_ERR_ASSOCINCOMPLETE = 27;
SE_ERR_DDETIMEOUT = 28;
SE_ERR_DDEFAIL = 29;
SE_ERR_DDEBUSY = 30;
SE_ERR_NOASSOC = 31;
}
end;