Solved

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

Posted on 1998-08-26
5
344 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
Comment Utility
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
Comment Utility
its setwindowshookex
0
 
LVL 2

Expert Comment

by:duneram
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

9 Experts available now in Live!

Get 1:1 Help Now