Alternative keyboard hook DLL self-installation hook

Source: Internet
Author: User
#pragma data_seg ()            static HHOOK g_hKeyboardHook = NULL;            static HINSTANCE g_hInst        = NULL;#pragma data_seg ()#pragma comment (linker, "/section:Shared, rws")BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) {     switch(fdwReason){       case DLL_PROCESS_ATTACH:       g_hInst =      (HINSTANCE) hInstance; 。。。。。

Then use two output functions: one installation hook and the other one uninstallation hook.

MY_API BOOL HookKey (){       ....       g_hKeyboardHook     = ::SetWindowsHookEx(WH_KEYBOARD, KeyboardProc,     g_hInst,     NULL);       ....}

CreateRemoteThread: Call the export function of the installation hook.

 

Lresult callback KeyboardProc (int nCode, WPARAM wParam, LPARAM lParam) {BOOL bKeyUp = lParam & (1 <31); // prevents, run the command if (bKeyUp & wParam = VK_HOME & nCode = HC_ACTION) once for both press and press on the keyboard) /////////////// /// // AfxMessageBox ("OK "); if (myform = NULL) {AFX_MANAGE_STATE (AfxGetStaticModuleState (); CWnd * pCWnd = CWnd: GetForegroundWindow (); myform = new CMyForm (); myform-> Create (IDD_MYFORM, pCWnd); myform-> ShowWindow (SW_SHOW);} else {myform-> ShowWindow (myform-> IsWindowVisible ()? SW_HIDE: SW_SHOW );} //////////////////////////////////////// /// //} return:: CallNextHookEx (g_hhook, nCode, wParam, lParam);} extern "C" _ declspec (dllexport) bool winapi InstallHook (HWND h) {if (g_hhook = NULL) {DWORD pmod; DWORD hThread = GetWindowThreadProcessId (h, & pmod); g_hhook =: SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC) KeyboardProc, theApp. m_hInstance, hThread); I F (g_hhook! = NULL) return TRUE;} return FALSE;} extern "C" _ declspec (dllexport) bool winapi InstallHook (HWND h) {if (g_hhook = NULL) {DWORD pmod; DWORD hThread = GetWindowThreadProcessId (h, & pmod); g_hhook =: SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC) KeyboardProc, theApp. m_hInstance, hThread); if (g_hhook! = NULL) return TRUE;} return FALSE ;}

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.