Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "dll.h"
- HINSTANCE hInstance = NULL; // The instance of the DLL
- LRESULT CALLBACK KeyboardMsgProc (int, WPARAM, LPARAM );
- #pragma data_seg(".SData")
- HHOOK hMsgHook = NULL;
- UINT KBoardMessage = NULL;
- HWND hParentWnd = NULL;
- #pragma data_seg( )
- #pragma comment(linker, "/SECTION:.SData,RWS")
- // then, a simple DllMain
- BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- if (ul_reason_for_call == DLL_PROCESS_ATTACH)
- hInstance = (HINSTANCE)hModule;
- return TRUE;
- }
- EXPORT int SetHook(HWND hWnd, UINT UpdateMsg)
- {
- if (hWnd == NULL) return -1;
- hParentWnd = hWnd;
- KBoardMessage = UpdateMsg;
- hMsgHook= SetWindowsHookEx(WH_GETMESSAGE, KeyboardMsgProc, hInstance, 0);
- if (hMsgHook == NULL)
- return -1;
- return 0;
- }
- EXPORT int UnSetHook()
- {
- UnhookWindowsHookEx (hMsgHook);
- hMsgHook = NULL;
- return 0;
- }
- LRESULT CALLBACK KeyboardMsgProc (int code, WPARAM wParam, LPARAM lParam)
- {
- if (code >= 0)
- {
- MSG *msg = (MSG *)lParam;
- if ((lParam) && (msg->message == WM_CHAR) && (wParam == PM_REMOVE))
- PostMessage (hParentWnd, KBoardMessage, msg->wParam, 0);
- }
- return CallNextHookEx(hMsgHook, code, wParam, lParam);
- }
Add Comment
Please, Sign In to add comment