PDA

Click to See Complete Forum and Search --> : Error handling


abdul
Aug 31st, 2001, 08:24 PM
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:


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?

Sc0rp
Aug 31st, 2001, 10:30 PM
Try this:

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);
}

abdul
Aug 31st, 2001, 11:23 PM
Thanks a lot!! It is working now:D

Sc0rp
Aug 31st, 2001, 11:57 PM
No problem. :)