Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Monitoring an application with C++

Hi,

I want to monitor an application written in MFC which crash some times, what I want to do is, get rid of Microsoft popup message and restart the program in monitor program, it's important the program is restart again automatically, cuz there is no operator around to restart the application, I tried to override ProcessWndProcException in the application but still get the popup, the application is a consol application , then I used __try __except in main , but still get the popup, I don't know when in code it crashes and don't want to go in all my code and add try and catch, I was looking at CreateProcess as well, but still it doesn't help to get rid of popup. So I am looking for a solution for monitoring and spawn my process, and if it crashes restart it again.

regards
/m
0
Marjaneh
Asked:
Marjaneh
  • 2
1 Solution
 
jkrCommented:
>>what I want to do is, get rid of Microsoft popup message and restart the program in monitor
>>program

IF you have the code to the MFC app, add

SetErrorMode(SEM_NOGPFAULTERRORBOX);

so the message box will not come up. Then, start it from a batch file like

@echo off
:respawn
start /WAIT c:\path\theapp.exe
goto respawn
0
 
MarjanehAuthor Commented:
Hi jkr,

Thanks for your comment, it doesn't work when crashes happend in a thread I guess, I tried to in our lab and I still get the popup, but when I simulate a null pointer exception in main in my computer it doesn't come up. I don't want to use batch file to monitor I want to have some statistic as well when it crashes, so I put that in both monitor program and in the main of MFC application.
I will investigate more and get back.

/BR
0
 
MarjanehAuthor Commented:
Hi jkr,
I added this command to the command you sugested and now it works, I think this one do the job  but because no one hase answered me so I will give you the points.
thank you.

you can use: SetUnhandledExceptionFilter( __XceptFilter);

which

LONG WINAPI __XceptFilter (EXCEPTION_POINTER *pExp)
{
......
return EXCPTION_EXECUTE_HANDLER; // or some other code
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now