Solved

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

Posted on 1998-08-26
5
347 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now