iportu
asked on
ShellExecute "open" on exception does not allow a force restart
I am writing a program which on an Unhandledexception, I want it to re-open itself again. For this I have created an exception filter:
long ProgExceptionFilter(EXCEPT ION_POINTE RS* p)
{
if(p->ExceptionRecord->Exc eptionCode ==EXCEPTIO N_ACCESS_V IOLATION
{
TCHAR(acModule[MAX_PATH];
GetModuleFileName(NULL, acModule, MAX_PATH);
ShellExecute(NULL, _T("open"), acModule, NULL, NULL, SW_SHOW);
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
This works but the problem is that the "restart" I had scheduled for 00:00 every day using (shutdown -r -f) no longer works because it cannot force the application with the above code to close.
Do yo have any ideas to overcome this problem?
Thank you .
long ProgExceptionFilter(EXCEPT
{
if(p->ExceptionRecord->Exc
{
TCHAR(acModule[MAX_PATH];
GetModuleFileName(NULL, acModule, MAX_PATH);
ShellExecute(NULL, _T("open"), acModule, NULL, NULL, SW_SHOW);
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
This works but the problem is that the "restart" I had scheduled for 00:00 every day using (shutdown -r -f) no longer works because it cannot force the application with the above code to close.
Do yo have any ideas to overcome this problem?
Thank you .
Previous approach would tie up your program to a specific time ... In case you need to restart at 2:00 AM instead, you would have to edit the code and recompile
Probably a better approach would be to define a signal handler (say for SIGINT) and send that signal to your process before restart.
Probably a better approach would be to define a signal handler (say for SIGINT) and send that signal to your process before restart.
ASKER
Sunnycoder. Yes, I had not thought about that. I thikn that to tidy things up too, the windows restart should happen within the program too - I'm checking whether that would work. Otherwise it would be a bit messy to close the program at a certain time and then set a windows routine for a certain time +5 minutes. It would get me what I want as you say but I think there must be a neater way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sunnycoder, thank you very much for your input. Jkr's solution worked very nicely though. It looks easy I suppose if you know it.
The signal handler for this alarm can make your application exit gracefully