views:

94

answers:

2

In my C++ application i use an activeX component that runs its own thread (or several I don't know). Sometimes this components throws exceptions. I would like to catch these exceptions and do recovery instead of my entire application crashing. But since I don't have access to its source code or thread I am unsure how it would be done.

The only solution I can think of is to run it in its own process. Using something like CreateProcess and then CreateRemoteThread, unsure how it could be implemented.

Any suggestion on how to go about solving this?

+2  A: 

If the ActiveX component is launching its own threads, then there isn't a lot that you can do. You could set a global exception handler and try to swallow exceptions, but this creates a high likelihood that your program state will become corrupted and lead to bizarre "impossible" crashes down the road.

Running the buggy component in a separate process is the most robust solution, as you'll be able to identify and recover from fatal errors without compromising your own program state.

JSBangs
The question then becomes. How do I create a new process and then inject the code it should run?
ronag
How are you hosting the ActiveX component now? If there is a command-line program that you already know of that can host it for you, then just launch that. Otherwise, you could write a small host of your own that only contains the bare minimum to run what you need. I can't say more than that without knowing the architecture of your application.
JSBangs
Its a FlashActiveX component which I use to render frames which my application processes. Its hosted using COM and ATL (I wasn't the one that wrote the hosting wrapper and have limited knowledge of its details). I dont know of any command-line program that can host it for me.If I understand you correctly the only way to accomplish this is through starting an external program?EDIT: http://casparcg.svn.sourceforge.net/viewvc/casparcg/Server/Development/trunk/server/producers/flash/See FlashAxContainer and FlashProducer
ronag
+1  A: 

Try setting up an exception filter with SetUnhandledExceptionFilter().

Michael J
How will I know from where the exception originated so that I can do proper recovery?
ronag
You can make a core dump, using MiniDumpWriteDump() (see http://msdn.microsoft.com/en-us/library/ms680360%28VS.85%29.aspx) or a stack trace using AfxDumpStack() (http://msdn.microsoft.com/en-us/library/ahbxfdc5%28VS.80%29.aspx).
Michael J