The ShellExecuteEx
Win32 function call has a flag SEE_MASK_FLAG_NO_UI
in its SHELLEXECUTEINFO
structure, which should suppress any error dialogs which could be displayed because of an error when launching an application.
The MSDN documentation here is quite explicit about it:
SEE_MASK_FLAG_NO_UI
0x00000400. Do not display an error message box if an error occurs.
In my case, I am launching a .NET executable on a Windows XP system where no .NET is installed. I systematically receive the following message, displayed by Windows in a dialog window:
Xxx.exe - Application Error
The application failed to initialize properly (0xc0000135).
Click on OK to terminate the application.
[ OK ]
I don't want the user to have to deal with this message. I'd rather get back an error code from ShellExecuteEx
and be able to handle it gracefully in my program. Here is the code snippet which I am using to start the external executable:
#include <windows.h>
int wmain(int argc, wchar_t* argv[])
{
SHELLEXECUTEINFO info;
memset(&info, 0, sizeof(SHELLEXECUTEINFO));
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_FLAG_NO_UI;
info.lpVerb = L"open";
info.lpFile = L"Xxx.exe";
info.nShow = SW_SHOW;
return ShellExecuteEx (&info);
}
Is there an official way of suppressing the error message if .NET is not present on the system? Or do I have to check for this specific condition myself before executing the application (but I do not know in advance if it is a .NET app or a native app). And what if the app I am starting is missing some DLLs, for instance?