473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Repost, Unanswered Hooking Problem...

TMP
Below is the code snippet that I'm having problems with, the hook seems to
work (hookResult returns a value other than zero) but then explorer
crashes.Also I'm aware of the fact that instead of specifying a dll with my
hook function embedded, I used my executable's module HINSTANCE. But I guess
no problem there since it works with different hook types.So can anyone
explain why explorer keeps crashing? (on Windows XP Professional) Thanks in
advance.

....

{
IntPtr taskBarHandle = IntPtr.Zero;

taskBarHandle = API.FindWindow("Shell_TrayWnd", null);

API.HOOKPROC msgHookProc = new TMP.WinXP.API.HOOKPROC(MsgHookProc);

GCHandle gcHandle = GCHandle.Alloc(msgHookProc, GCHandleType.Normal);
uint threadId = 0;

uint processId = 0;

threadId = API.GetWindowThreadProcessId(taskBarHandle, out processId);

if(threadId != 0)

hookResult = API.SetWindowsHookEx(API.WH_GETMESSAGE,
msgHookProc,Marshal.GetHINSTANCE((typeof(Form1).Mo dule)), threadId);

Console.WriteLine("Hook Result = " + hookResult.ToString());

}

....

private IntPtr MsgHookProc(int nCode, IntPtr wParam, IntPtr lParam)

{

if(nCode < 0 )

return API.CallNextHookEx(hookResult, nCode, wParam, lParam);
API.MSG message = (API.MSG) Marshal.PtrToStructure(lParam, typeof(API.MSG));

MessageBox.Show(message.pt.x.ToString());
return API.CallNextHookEx(hookResult, nCode, wParam, lParam);

}

Nov 15 '05 #1
1 1176
Hi TMP,
I just answered your previoust post

--
B\rgds
100 [C# MVP]

"TMP" <de*****@nospam.com> wrote in message
news:O0*************@tk2msftngp13.phx.gbl...
Below is the code snippet that I'm having problems with, the hook seems to
work (hookResult returns a value other than zero) but then explorer
crashes.Also I'm aware of the fact that instead of specifying a dll with my hook function embedded, I used my executable's module HINSTANCE. But I guess no problem there since it works with different hook types.So can anyone
explain why explorer keeps crashing? (on Windows XP Professional) Thanks in advance.

...

{
IntPtr taskBarHandle = IntPtr.Zero;

taskBarHandle = API.FindWindow("Shell_TrayWnd", null);

API.HOOKPROC msgHookProc = new TMP.WinXP.API.HOOKPROC(MsgHookProc);

GCHandle gcHandle = GCHandle.Alloc(msgHookProc, GCHandleType.Normal);
uint threadId = 0;

uint processId = 0;

threadId = API.GetWindowThreadProcessId(taskBarHandle, out processId);

if(threadId != 0)

hookResult = API.SetWindowsHookEx(API.WH_GETMESSAGE,
msgHookProc,Marshal.GetHINSTANCE((typeof(Form1).Mo dule)), threadId);

Console.WriteLine("Hook Result = " + hookResult.ToString());

}

...

private IntPtr MsgHookProc(int nCode, IntPtr wParam, IntPtr lParam)

{

if(nCode < 0 )

return API.CallNextHookEx(hookResult, nCode, wParam, lParam);
API.MSG message = (API.MSG) Marshal.PtrToStructure(lParam, typeof(API.MSG));
MessageBox.Show(message.pt.x.ToString());
return API.CallNextHookEx(hookResult, nCode, wParam, lParam);

}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Seth Gecko | last post by:
Hi I want to make an application (in C#) that can catch text written to a Richedit control in another application. Using Spy++ I can see that the message I want to intercept is called...
1
by: Matthew Kelly | last post by:
I have pulled together a VB.net project that hooks the keyboard (Ref. Paul Kimmel's hooking program) and allow the user to send "mouse right clicks" via the SendInpuut function (mouse emulation...
3
by: Adam | last post by:
I've posted about this previously, but failed to receive a satisfactory response, so have included a code sample: I am trying to receive messages from an HTML viewer control in compact.net (c#),...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
3
by: CanoeGuy | last post by:
Why do some questions go unanswered? I'm trying to get some help with a problem that I'm having and am getting nowhere!!!! -- Joe Goeke
0
by: Nico Debeuckelaere | last post by:
Hi all, I created in the past a custom tool in Visual Studio 2002. This was actually an enhancement on the MSDatasetGenerator and always worked fine. Now I converted the project to Visual...
5
by: Ryan Ginstrom | last post by:
Apropos recent threads about GUI editors, coming from a Win32/WTL C++ background, I actually like the idea of being able to (easily) create GUIs programmatically. But I still see a lot of the...
8
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse...
1
by: D-Someone | last post by:
I am re-posting this message as originially it did not get a single response.. Any ideas? -------------- I am trying to come up with a good design for a web service that has some user logic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.