Solved

Need to get all messages in applicationat a high level...

Posted on 1998-08-26
5
351 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:woodsnick
  • 5
5 Comments
 
LVL 2

Accepted Solution

by:
duneram earned 200 total points
ID: 1413937
Install a hook using SetWindowsEx and WH_MESSAGE

That will catch all messages.  YOu can do it app wide or system wide.  You will catch all messages depending on how you set it up.

0
 
LVL 2

Expert Comment

by:duneram
ID: 1413938
its setwindowshookex
0
 
LVL 2

Expert Comment

by:duneram
ID: 1413939
You can get samples of it at http://support.microsoft.com/support/kb/articles/q81/3/32.asp

article  Q81332 and Q74547

in 32 bits the usage of hooks (high level) are pretty much the same with some exceptions.

0
 
LVL 2

Expert Comment

by:duneram
ID: 1413940
Use this parameter:
WH_GETMESSAGE Installs a hook procedure that monitors messages posted to a message queue.  It can be a system wide monitor or just an application.  SetWindowsHookEx is the Key API.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1413941
if you use the WH_MSGFILTER parameter, it installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar.  
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question