Guest User

Untitled

a guest
Nov 26th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include "dll.h"
  2.  
  3. HINSTANCE hInstance = NULL; // The instance of the DLL
  4. LRESULT CALLBACK KeyboardMsgProc (int, WPARAM, LPARAM );
  5.  
  6.  
  7. #pragma data_seg(".SData")
  8. HHOOK hMsgHook = NULL;
  9. UINT KBoardMessage = NULL;
  10. HWND hParentWnd = NULL;
  11. #pragma data_seg( )
  12.  
  13. #pragma comment(linker, "/SECTION:.SData,RWS")
  14.  
  15. // then, a simple  DllMain
  16. BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  17. {
  18.     if (ul_reason_for_call == DLL_PROCESS_ATTACH)
  19.         hInstance = (HINSTANCE)hModule;
  20.  
  21.     return TRUE;
  22.  }
  23.  
  24. EXPORT int SetHook(HWND hWnd, UINT UpdateMsg)
  25. {
  26.     if (hWnd == NULL) return -1;
  27.  
  28.     hParentWnd = hWnd;
  29.     KBoardMessage = UpdateMsg;
  30.  
  31.     hMsgHook= SetWindowsHookEx(WH_GETMESSAGE, KeyboardMsgProc, hInstance, 0);
  32.  
  33.     if (hMsgHook == NULL)
  34.         return -1;
  35.     return 0;
  36.  }
  37.  
  38. EXPORT int UnSetHook()
  39. {
  40.     UnhookWindowsHookEx (hMsgHook);
  41.     hMsgHook = NULL;
  42.     return 0;
  43. }
  44.  
  45. LRESULT CALLBACK KeyboardMsgProc (int code, WPARAM wParam, LPARAM lParam)
  46. {
  47.     if (code >= 0)
  48.     {
  49.         MSG *msg = (MSG *)lParam;
  50.  
  51.         if ((lParam) && (msg->message == WM_CHAR) && (wParam == PM_REMOVE))
  52.             PostMessage (hParentWnd, KBoardMessage, msg->wParam, 0);
  53.     }
  54.  
  55.     return CallNextHookEx(hMsgHook, code, wParam, lParam);
  56. }
Add Comment
Please, Sign In to add comment