-
Error handling
I am using "ShellExecute" to open a file but I want to show an error message whenever the path or file is invalid or some other error occurs. How do I do that?
I have tried the following line of code but even if the specific path is valid, it still shows the error message:
Code:
if(ShellExecute(hwnd, "open",combotext,NULL,NULL, SW_NORMAL)==(HINSTANCE)ERROR_FILE_NOT_FOUND || (HINSTANCE)ERROR_PATH_NOT_FOUND || (HINSTANCE)ERROR_PATH_NOT_FOUND)
{
MessageBox(hwnd, "The specified file name or path was not found, or there is not enough memory to run this program. Please try again"
, "Error!!", MB_OK | MB_ICONERROR);
}
When I type "C:\" as the path, it opened The contents of C: but still showed me the message box. How do you fix that?
-
Try this:
PHP Code:
HINSTANCE tempRes = ShellExecute(hwnd, "open",combotext,NULL,NULL, SW_NORMAL);
if ((long)tempRes <= 32) // Validate file
{
// Error!!!
MessageBox(hwnd, "An error occured while trying to access this file.", "Error", MB_OK | MB_ICONERROR);
}
-
Thanks a lot!! It is working now:D
-