Advertisement

06.06.2008 at 07:26AM PDT, ID: 23463815
[x]
Attachment Details

Cancelling messages with CallWndProc

Asked by AndrewVos in Microsoft Visual C++.Net, Microsoft Visual C#.Net, Visual Studio 2008

Tags: C++ 2008, C# 2008

I've created a library in c++ 2008, which uses SetWindowsHookEx and CallWndProc.

I'm attempting to stop some messages from being processed, and can't seem to get it right.

I've trimmed the code down a bit, but basically all this code is in dllmain.

Also, I'm running StartHook and StopHook from a c# app using pinvoke.

I am definitely receiving the messages, which you can check by uncommenting the messagebox code at the bottom (be careful with this though, it will most likely crash your system. Try it in a virtual machine if you have to!)

Any ideas?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:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
 
LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam);
HHOOK myHook = NULL;
HMODULE myModule = NULL;
 
extern "C" void _declspec(dllexport) StartHook(){
  if (myHook == NULL){
    myHook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)CallWndProc,myModule,0);
  }
}
extern "C" void _declspec(dllexport) StopHook(){
  if (myHook != NULL){
    UnhookWindowsHookEx(myHook);
  }
}
 
BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved){
  switch (ul_reason_for_call)	{
  case DLL_PROCESS_ATTACH:
    myModule = hModule;
    break;
  case DLL_THREAD_ATTACH:
    break;
  case DLL_THREAD_DETACH:
    break;
  case DLL_PROCESS_DETACH:
    StopHook();
    break;
  }
  return TRUE;
}
 
LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam){
  if (nCode < 0){return CallNextHookEx(myHook,nCode,wParam,lParam);}
 
  BOOL cancelMessage = false;
 
  CWPSTRUCT* pwp = (CWPSTRUCT*)lParam;
 
  switch(pwp->message){
    case WM_SIZING:
      cancelMessage  = TRUE;
      break;
    case WM_SIZE:
      cancelMessage  = TRUE;
      break;
  }
 
  if (!cancelMessage){
    return CallNextHookEx(myHook,nCode,wParam,lParam);
  }else{
    return 1; //This doesn't work
   // MessageBox(0,L"Message Cancelled",L"Cancelled",MB_OK);
  }
}
 
 
Loading Advertisement...
 
[+][-]06.06.2008 at 01:22PM PDT, ID: 21732387

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.

 
[+][-]06.06.2008 at 10:47PM PDT, ID: 21734390

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.

 
[+][-]06.06.2008 at 10:56PM PDT, ID: 21734406

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.

 
[+][-]06.07.2008 at 09:44AM PDT, ID: 21736097

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.

 
[+][-]06.07.2008 at 02:24PM PDT, ID: 21736826

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.

 
[+][-]06.07.2008 at 02:25PM PDT, ID: 21736828

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.

 
[+][-]06.13.2008 at 08:39PM PDT, ID: 21783976

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

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

 
[+][-]06.17.2008 at 04:50PM PDT, ID: 21808471

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

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

 
[+][-]06.18.2008 at 02:59AM PDT, ID: 21811364

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.

 
[+][-]06.18.2008 at 06:04AM PDT, ID: 21812343

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.

 
[+][-]06.18.2008 at 12:55PM PDT, ID: 21816481

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.

 
[+][-]06.18.2008 at 03:15PM PDT, ID: 21817795

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, Microsoft Visual C#.Net, Visual Studio 2008
Tags: C++ 2008, C# 2008
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.19.2008 at 03:00AM PDT, ID: 21820695

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.

 
[+][-]06.19.2008 at 03:03AM PDT, ID: 21820710

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