Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


getModuleHandle()
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
miclus
How do I cheat?
Reputation: 0

Joined: 25 Dec 2010
Posts: 1

PostPosted: Sat Dec 25, 2010 7:31 pm    Post subject: Reply with quote

Hey, guys. I found this code on another forum by a Dark_Mage:

Code:

HMODULE GetRemoteModuleHandle(unsigned long pId, char *module)
{
   MODULEENTRY32 modEntry;
   HANDLE tlh = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pId);

   modEntry.dwSize = sizeof(MODULEENTRY32);
    Module32First(tlh, &modEntry);

   do
   {
      if(!stricmp(modEntry.szModule, module))
         return modEntry.hModule;
      modEntry.dwSize = sizeof(MODULEENTRY32);
   }
   while(Module32Next(tlh, &modEntry));

   return NULL;
}


Anyway, it works for me ok on my XP machine, but doesn't work on my 98 machine. Does anyone know some equivalent code that will work on Windows 98?

Edit: Ok, the problem was the PID I got was invalid due to Windows 98 using full paths for the process list. Anyway, I made some code if anyone needs help getting the process ID or module handle:

Code:


/*

    This code illustrates how to get a process ID and module handle
    for a given process (by name).

*/

#include <iostream>
#include <string>
#include <windows.h>
#include <Tlhelp32.h>

//This function returns a process ID for a given process name.
//Thanks to Darawk for his code.

DWORD GetProcessID(const char* processName)
{

    HANDLE H = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 P;
    P.dwSize = sizeof(PROCESSENTRY32);

    Process32First(H, &P);
   
    do
    {

        //On older OS's, such as Win98, the process
        //list includes path information.  So, we strip that info out.

        std::string x = P.szExeFile, y = P.szExeFile;
        size_t f = x.rfind("\\");

        if (f != std::string::npos)
            y = x.substr(f + 1);

        if(!stricmp(processName, y.c_str()))
            return P.th32ProcessID;
       
    } while(Process32Next(H, &P));

    return 0;
}

//This function returns the module handle for a given process ID and module name.
//Thanks to Darawk for his code.

HMODULE GetRemoteModuleHandle(DWORD PID, const char* moduleName)
{

    HANDLE H = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
    MODULEENTRY32 M;
    M.dwSize = sizeof(MODULEENTRY32);

    Module32First(H, &M);

    do
    {

        if(!stricmp(M.szModule, moduleName))
            return M.hModule;

        M.dwSize = sizeof(MODULEENTRY32);

    } while(Module32Next(H, &M));

    return NULL;

}

//Example usage.

int main()
{

    char name[81];
    HANDLE H;
    DWORD PID;

    while (1)
    {

        std::cout << "\n\nEnter a process name:  ";
        std::cin.getline(name, 80);

        PID = GetProcessID(name);
        H = GetRemoteModuleHandle(PID, name);

        std::cout << "\nProcess ID:     " << PID;
        std::cout << "\nModule Handle:  " << H;

    }

    return 0;

}

Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sun Dec 26, 2010 12:52 pm    Post subject: Reply with quote

No offense but why are still developing on Win98 machine(s)? They haven't been supported for years.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites