Advertisement
Guest User

dll low level HOOK

a guest
Aug 11th, 2010
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #ifndef _DLL_HOOKER
  2. #define _DLL_HOOKER
  3.  
  4.  
  5. #include<Windows.h>
  6.  
  7. static HHOOK hHook;
  8.  
  9. typedef void (*FuncHandle)(int,int);
  10.  
  11. static FuncHandle Handler = NULL;
  12.  
  13. LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);
  14.  
  15. BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  16. {
  17.     switch (dwReason)
  18.     {
  19.         case DLL_PROCESS_ATTACH:
  20.             DisableThreadLibraryCalls(hInstance);
  21.             hHook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc, hInstance, NULL);
  22.         break;
  23.  
  24.         case DLL_PROCESS_DETACH:
  25.             UnhookWindowsHookEx(hHook);
  26.         break;
  27.     }
  28.     return true;
  29. }
  30.  
  31. LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
  32. {
  33.     if (nCode >= 0 && LOWORD(wParam) == WM_KEYDOWN)
  34.     {
  35.         if(Handler)
  36.         {
  37.             KBDLLHOOKSTRUCT St = *(KBDLLHOOKSTRUCT *)lParam;
  38.             (*Handler)(St.vkCode, St.flags);
  39.         }
  40.     }
  41.     return CallNextHookEx(NULL, nCode, wParam, lParam);
  42. }
  43.  
  44. extern "C" __declspec(dllexport) void CALLBACK SetHandler(FuncHandle handlerfunc)
  45. {
  46.     Handler = handlerfunc;
  47. }
  48.  
  49. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement