Sounds to me like you are instantiating a globalKeyboardHook then letting it get garbage collected. I'm guessing you do something like this.
Sounds to me like you are instantiating a globalKeyboardHook then letting it get garbage collected. I'm guessing you do something like this: public void InstallHook() { var hook = new globalKeyboardHook(); } You need to keep a reference to the globalKeyboardHook() around to prevent it from being garbage collected. GlobalKeyboardHook hook; public void InstallHook() { hook = new globalKeyboardHook(); }.
1 It will still hit this scenario when the object holding the reference goes out of scope. The solution really needs to include IDisposable. – hemp May 31 at 21:46.
Since it looks like my guess may have been right, I'll add some more detail: Up at the top, where you define your member variables, add one more like this: IntPtr hhook = IntPtr. Zero private keyboardHookProc hookProcDelegate; then change your constructor to be: public globalKeyboardHook() { hookProcDelegate = hookProc; hook(); } and then change your hook() method to be: public void hook() { IntPtr hInstance = LoadLibrary("User32"); hhook = SetWindowsHookEx(WH_KEYBOARD_LL, hookProcDelegate, hInstance, 0); } That way you're using a delegate that is stored as a member variable and will be alive as long as your globalKeyboardHook object is alive.
You are not wrong. – Hans Passant Jun 1 at 1:21 well how do I keep it in the managed world? – Chris Jun 1 at 2:45 I've added more detail to my answer.
– Tim Jun 1 at 13:28.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.