hi i am using the following functions to get a module handler by a name or by a window title:
Code:
HMODULE getModule(DWORD processID, char* searchStr){ // gets the module by the modul name from an explicit process
HANDLE hProcess;
HMODULE hMods[1024];
TCHAR szModName[MAX_PATH];
DWORD cbNeeded;
if(hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ))
if(EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
for(unsigned int k = 0; k < (cbNeeded / sizeof(HMODULE)); ++k )
if (GetModuleFileNameEx(hProcess, hMods[k], szModName, sizeof(szModName)/sizeof(TCHAR)))
if(strstr(szModName, searchStr)){
printf( "pid: %u modname: %s\n", processID, szModName );
CloseHandle( hProcess );
return hMods[k];
}
CloseHandle( hProcess );
return NULL;
}
HMODULE getModule(char* searchStr){ // gets the module by the modul name from all processes
DWORD aProcesses[1024], cbNeeded, cProcesses;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return NULL;
cProcesses = cbNeeded / sizeof(DWORD);
HMODULE hmodule;
for (unsigned int i = 0; i < cProcesses; ++i )
if(hmodule = getModule(aProcesses[i], searchStr)) return hmodule;
return NULL;
}
HMODULE getModule(HWND hwnd){ // gets the module from a window
DWORD pid = GetWindowThreadProcessId(hwnd, NULL ); // !!??!!
printf( "hwnd pid: %u\n", pid );
return getModule(pid, ".exe");
}
HMODULE hModuleT;
char* searchStrT;
BOOL CALLBACK shownWindow(HWND hwnd, LPARAM lParam){ // EnumWindows callback
if(hModuleT) return true;
char pcWinTitle[256];
if(GetWindow(hwnd, GW_OWNER)) return true; // whats that?
GetWindowText(hwnd, pcWinTitle, 1024);
if(strstr(pcWinTitle, searchStrT)){
printf( "wndtitle: %s\n", pcWinTitle);
hModuleT = getModule(hwnd);
}
return true;
}
HMODULE getModuleByWndTitle(char* searchStr){ // gets the module from a window title
searchStrT = searchStr;
EnumWindows(shownWindow, 0);
return hModuleT;
}
but if i run:
Code:
printf("find by name ... \n");
getModule("proton.exe");
printf("\nfind by title ... \n");
getModuleByWndTitle("Proton");
i get this output:
find by name ...
pid: 3564 modname: d:\programme\proton\proton.exe
find by title ...
wndtitle: Proton
hwnd pid: 3568
what does GetWindowThreadProcessId return? is that not the correct process id?