3

I create a COM object used for automation tasks of some application. When this happens application is started and its' main window is displayed.

The problem happens when user closes the main application window. Next Invoke call to the COM object does not work. The problem is that it does not fail and it does not report an error. If I put a debugger breakpoint in next line of code, it is never reached. If I surround the Invoke call with try/catch, no exception is caught. In release build it just crashes.

How is this supposed to work? Since I use CComDispatchDriver as a wrapper around IDispatch* I would expect that my AddRef would keep the COM object alive even if user closed the application. I was hoping of at least getting some HRESULT as an error.

bombardier
  • 905
  • 3
  • 9
  • 19
  • Clearly you are dealing with a cr*ppy COM server. It is supposed to keep running and pumping a message loop until you release the app object. You'd better respond to some kind of "exit" event. If there isn't one then you'll need the vendor's support. – Hans Passant Sep 23 '11 at 09:37
  • There is no events. Since this is out of proc call, is it to much to expect that Invoke returns an error when it doesn't find destination message loop? – bombardier Sep 23 '11 at 10:59
  • COM stubs are very thin, no timeouts. Contact the vendor, you can't be the only one with this problem. – Hans Passant Sep 23 '11 at 11:46
  • As a workaround, I assume there is a way to identify the process you are communicating with. You could then open a handle to it to monitor whether it is still running or not. (This probably won't be 100% reliable due to race issues but might be better than nothing.) – Harry Johnston Sep 24 '11 at 03:18
  • The timeout will appear in (default of) 9-10 minutes; You can decrease the timespan on a global or local basis, if you can be sure that the other end is not on a 486 behind a dial-up-POTS-modem (That's why the default is so high) – aquaherd Sep 26 '11 at 19:29

1 Answers1

0

What probably happened is that your application called CoUninitialize when exiting. CoUninitialize causes all COM object to be discarded, thus if you ever interact with the COM object after calling CoUninitialize, you'll crash.

Larry Osterman
  • 16,086
  • 32
  • 60