Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have tryed to use the GetModuleInformation, but every time I used it, the application crash.

My code:

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

using namespace std;

HMODULE GetRemoteModuleHandle(DWORD lpProcessId, LPCSTR lpModule);

int main() {
  HWND hWnd = FindWindow(0, "Counter-Strike Source");
    if(hWnd == 0){
      MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
    } 
    else {
      DWORD proccess_ID;
      GetWindowThreadProcessId(hWnd, &proccess_ID);


      HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
      HMODULE hModule = GetRemoteModuleHandle(proccess_ID, "engine.dll");

      MODULEINFO mi;
      GetModuleInformation(hProcess, hModule, &mi, sizeof(mi));
   }   
   return 0;
}

HMODULE GetRemoteModuleHandle(DWORD lpProcessId, LPCSTR lpModule)
{
    HMODULE hResult = NULL;
    HANDLE hSnapshot;
    MODULEENTRY32 me32;

    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, lpProcessId);
    if (hSnapshot != INVALID_HANDLE_VALUE)
    {
        me32.dwSize = sizeof(MODULEENTRY32);
        if (Module32First(hSnapshot, &me32))
        {
            do
            {
                if (!stricmp(me32.szModule, lpModule))
                {
                    hResult = me32.hModule;
                    break;
                }
            }
            while (Module32Next(hSnapshot, &me32));
        }
        CloseHandle(hSnapshot);
    }
    return hResult;
}


The Handle to the Module isn't NULL so I think it is created! :O
I hope you can help me :)
Posted
Updated 25-Jul-11 12:01pm
v3

1 solution

I suggest that you run it under the debugger, and put a break-point on the line where you call that function.
 
Share this answer
 
Comments
HartzFear 25-Jul-11 19:06pm    
yes i do it, but i can't debug this function because it is part of the psapi.lib -.-
..after this function, btw. in the function the programm crash...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900