This is some background description of what is going on in my application, the actual bit I am trying get an answer for follows it:
I have an application which communicates with an OLE server, which is a Netscape plugin, through OLE automation. The problem I am running into is that when I press the back button in the browser the plugin shuts down and my application which is running and doing the drawing for the plugin can be running and in a suspended state (say with a message box up) but the OLE destruction causes the application to become re-entrant (I get into the main application message loop even though part of it is still in a modal dalog box). When a user then later decides to close the message box the memory from underneath it has been destroyed because of the destruction that occurs when the OLE calls make the application re-entrant. What I do right now is override PreTranslate message to handle all application messages and set a busy flag while ::TranslateMessage and ::DispatchMessage are active and then I clear it later.
I was assuming that every message in my application had to go through PreTranslate message, so I could basically determine whenever anything was going on in my app and when that exited I could then free up the memory. Unfortunately when looking at the call stack during some of the bad memory accesses in my app following the dismissal of a modal dialog that was up before the plugin shutdown I see my application having entered the point the the main AfxWndProc without PreTranslateMessage on the stack.
I can only assume this means that messages are being sent more directly to a window in my application, so my question is this: How can I provide a handler for my app that can be notified whenever any message is going on. If I override the main windows message handler and insert my busy checking will that cover it? Can I override the AfxWndProc and if so how? I want to know when messages in my main apps window or any of its child windows are ocurring so I don't free things up until they have finished.
If you have a solution to my problem or a partial solution to the problem, please let me know ASAP.