So,
I have tried to do some basic steps in windows hooking and wrote the
following code. This works fine, at least for some seconds, then the
application freezes and the explorer process is killed =D, what am I doing
wrong?
The hook callback delegate:
public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
setting up the hook:
HookProc p = new HookProc(this.C allbackFunction );
this.hook = SetWindowsHookE x(HookType.WH_C ALLWNDPROC, p,
Marshal.GetHINS TANCE(typeof(Cl ass1).Module),0 );
Callback implementation:
private int CallbackFunctio n(int code, IntPtr wParam, IntPtr lParam)
{
if (code < 0)
{
return CallNextHookEx( this.hook, code, wParam, lParam);
}
int ret;
try
{
Message msg = (Message)Marsha l.PtrToStructur e(lParam, typeof(Message) );
Console.WriteLi ne(msg);
}
catch
{
Console.WriteLi ne("exception") ;
}
finally
{
ret = CallNextHookEx( this.hook, code, wParam, lParam);
}
return ret;
}
Regards Alexander
"Andrew Kirillov" wrote:
Hello
If you want to trap windows messages of another application you should look
at hooks.
Here you can find more information:
1)
http://msdn.microsoft.com/library/de...asp?frame=true
2) http://www.codeproject.com/csharp/GlobalSystemHook.asp
3) http://www.codeproject.com/system/hooksys.asp
--
With best regards,
Andrew
http://www.codeproject.com/script/pr...asp?id=1181072
"Alexander Wehrli" <Al************ *@discussions.m icrosoft.com> wrote in
message news:12******** *************** ***********@mic rosoft.com... Hi,
I need to write a functionality to catch all Windows Messages from any
Window (like spy++ does). I thought that would be possible by subclassing
the
window.
So I wrote a class that inherts from NativeWindow, Assigned a Handle from
another window and overrode the WndProc method.
BUT, I never catch any message EXCEPT if I assign the handle of my own
application's window...
Has anyone done something like this before?
I'm stuck at the moment....
Regards Alexander