Archiv

Posts Tagged ‘unmanaged code’

Global System Hooks in C#

16. November 2011 Hinterlasse einen Kommentar

Currently I am programing a shell replacement for Windows 7 with WPF and C#. Low Level hooking to the mouse and keyboard is very simple, but message and shell hooking does not work at all. I did some research (Google) and found out that it is not possible in C#.
Then I found this article:
Using Window Messages to Implement Global System Hooks in C# from ChrisP1118.
He is basically using the Desktop window handle (with the help of SetProp and GetProp) to store the hWnd that is shared between the instances of the callbacks. It works very well. But there is a big problem. It depends on the desktop availability. Which does not exists if I’m using an other shell.
In his article he mentioned that he originally wanted to solve the problem with sharing memory.
Well I took his code and with the big help from
Microsoft I was able to implement memory sharing.

image

OK… I know… even a six years old could have done that… Easy stuff…

Source Code

WilsonGlobalSystemHooksWithSharedMemory_src.zip

Advertisements