2. Add a keyboard hook. Injecting DLLs into the process

Source: Internet
Author: User

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

Related Article

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.