Study Notes
1. First, the dynamic link Library of MFC should be established. Put the name of the function you want to export in the Def file.
2. Add the function as follows
//Mounting Hooks//Hhook SetWindowsHookEx (//int Idhook,//Types of Hooks Wh_keyboard keyboard hooks//HOOKPROC LPFN,//Hook callback function, hook type different callback function//hinstance hwnd,//handle to DLL dynamic link library//DWORD dwThreadID//The ID of the main process of the game is the return value of GetWindowThreadProcessId// )//callback function corresponding to the keyboard hookLRESULT CALLBACK Gameproc (intCode,wparam WPARAM,//key codes, such as F12=vk_f12LPARAM LPARAM//key-related information. Specific Baidu){ //use the API in MFC to add this macro!!!! afx_manage_state (AfxGetStaticModuleState ()); //You can also add logic that is executed after the key is pressed if((WPARAM==VK_F12) && (lparam& (1<< to)==0))//the 31st digit of the lparam is removed 0 is pressed{AfxMessageBox (L"Press the F12"); } returnCallNextHookEx (0, Code,wparam,lparam);}#defineGamename L "Yb_onlineclient"//macro Definition window namevoidsethook () {//use the API in MFC to add this macro!!!! afx_manage_state (AfxGetStaticModuleState ()); //Get Window HandleHWND gameh=:: Findwindoww (Null,gamename); //Get thread IDDWORD gameid=GetWindowThreadProcessId (gameh,null); //thread hook The third parameter cannot be 0, and the fourth parameter is 0 is the global hook. //:: Getmodulehandlea ("MyDLL.DLL") get handle to dynamic link library:: Setwindowshookexw (Wh_keyboard,&gameproc,::getmodulehandlea ("MyDLL.DLL"), GameID);}
3. New Window program add hooks.
3.1 Copy DLL and lib files generated by dynamic link library to the Windows program's release file or under the root directory or under debug
3.2 Add the following program
#pragma comment (lib, "Mydll.lib")// Introducing DLL to the link library void sethook (); // Declaration of the import function void Crxjhcdlg::onbnclickedbuttonsethook () { // TODO: Add control notification handler code here Sethook ();}
2. Add a keyboard hook. Injecting DLLs into the process