I made two functions: one to get process id and the other to get a handle with all access to that process using the process id. I'm looking for help with making these easy to use on all types of projects. The only thing I know is maybe letting the person chose the open process properties.
DWORD getProcID(const std::wstring &windowName, std::string &status)
{
DWORD processID = NULL;
HWND windowHandle = NULL;
windowHandle = FindWindowW(NULL, windowName.c_str()); // Gets handle to top window (class name, window name)
if (windowHandle) {
GetWindowThreadProcessId(windowHandle, &processID); // returns thread that made window (window, process for window)
if (processID != 0) {
return processID;
}
else { // if process id is bad
status = "Error with process";
return 0;
}
}
else { // if window name is bad/not there
status = "Error with window";
return 0;
}
CloseHandle(windowHandle); // close window handle since we dont need it anymore
return 0;
}
HANDLE &getProcessHandle(const DWORD processID, std::string &status) {
HANDLE procHandle = NULL;
if (processID != 0) {
procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); // returns handle to process (what you want, inherit stuff, process id)
if (procHandle != INVALID_HANDLE_VALUE || procHandle != NULL) { // if handle returned by openProcess is good
status = "Game is ready to hack";
}
else { // if handle retured by openProcess is bad
status = "Error with handle";
}
}
else {
status = "Error with process id";
}
return procHandle;
}