The second parameter is NOT the HINSTANCE of the appliction you want to hook, but the HINSTANCE of the dll contaning the hook procedure. so you can write a DllMain function, and store the HINSTANCE of the dll in a global viriable.when you call SetWindowsHookEx, use the global viriable as the second parameter.