Advertisement

05.19.2008 at 05:11PM PDT, ID: 23415574
[x]
Attachment Details

Global Hook Spam

Asked by jjharr in Microsoft Visual C++.Net, Windows Programming, Kernel And Operating System Specific Programming

Tags: Microsoft, Visual C++, 8, win32, c++, win32, visual c++, hooks, system

I'm a newbie win32 developer who's implemented a global hook for WM_ACTIVATEAPP. The MS documentation led me to believe that this notification is dispatched once each to the application being activated and the application being deactivated. But I seem to be getting about 5-20 calls to the callback for each application involved in each focus change.

Is this normal or am I likely doing something wrong? If it is normal, is there an accepted way of filtering or I am stuck with trying to implement a shared variable with the current state and doing a diff against it every time I get a message?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
DECLDIR LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
   {
 
	   if(nCode == HC_ACTION){
 
		   CWPSTRUCT *msg = reinterpret_cast<CWPSTRUCT *>(lParam);
 
		   if(msg->message == WM_ACTIVATEAPP){
				
				struct appActiveEvent *notification = (struct appActiveEvent*)malloc(sizeof(appActiveEvent));
 
			   if(msg->wParam){
 
				   notification->pid = GetCurrentProcessId();
 
 
				   DWORD bufSz = sizeof(notification->appName);
				   if( GetModuleFileName(NULL, notification->appName, bufSz) >= bufSz)
					   notification->appName[wcslen(notification->appName)-1] = NULL;
				   
                                   // This gets called about 10x per focus change event
				   WriteEventToFile(notification);
			   }
			   
			   free(notification);
			   // only care about app being activated, so do nothing in the else case
		   }
	   }
 
	   return CallNextHookEx(NULL, nCode, wParam, lParam);
   }
[+][-]05.20.2008 at 08:23AM PDT, ID: 21607045

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:42PM PDT, ID: 21610941

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 02:25PM PDT, ID: 21619158

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 03:35PM PDT, ID: 21619602

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 05:04PM PDT, ID: 21619984

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 06:01PM PDT, ID: 21620175

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C++.Net, Windows Programming, Kernel And Operating System Specific Programming
Tags: Microsoft, Visual C++, 8, win32, c++, win32, visual c++, hooks, system
Sign Up Now!
Solution Provided By: JohnGaby
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.22.2008 at 04:55AM PDT, ID: 21622895

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628