#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 ;}