Obtain the first address of the target process.

Source: Internet
Author: User

Obtain the first address of the target process.

Add the following code to the header file:

#include <windows.h> #include <tlhelp32.h> 

Add the following function to the Cpp file to obtain the first address of the target process:

(Note that AfxMessageBox is defined in afxwin. h. If it is not used in MFC, change it as appropriate)

// Obtain the first address of the target process, BOOL CImageBloodDlg: getProcessAddr (DWORD dwPID, DWORD & baseAddr) {HANDLE hModuleSnap = INVALID_HANDLE_VALUE; MODULEENTRY32 me32; // obtain the snapshothModuleSnap = snapshot (TH32CS_SNAPMODULE, dwPID) of all processes in the target process; if (hModuleSnap = snapshot) {AfxMessageBox (_ T ("createconlhelp32snapshot (of modules) fail "); return (FALSE);} // set the MODULEENTRY32 Data Structure size field me32.dwSize = sizeof (MODULEE NTRY32); // retrieves the information of the first module. if (! Module32First (hModuleSnap, & me32) {AfxMessageBox (_ T ("Module32First fail"); // display CloseHandle (hModuleSnap) for failed calls ); // clear the handle object return (FALSE);} // get the base address baseAddr = (DWORD) me32.modBaseAddr from me32; // do not forget to clear the module handle object CloseHandle (hModuleSnap ); return (TRUE );}

Call this function to obtain the first address of the target process.

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.