Error while trying to get current active window
So I'm trying to get the active process (no admin privileges needed I think) and both hwnd and pID aren't NULL and the issue seems to be at this line:
if (GetModuleBaseNameA(Handle, NULL, processName, sizeof(processName) / sizeof(char)))
std::string features::GetCurrentActiveProcess(Buffer* buffer)
{
//handle to foreground window
HWND hwnd = GetForegroundWindow();
if (!hwnd)
{
std::cout << "No active window.\n";
return "No active window.\n";
}
std::cout << hwnd << "\n";
//getting process ID
DWORD pID;
GetWindowThreadProcessId(hwnd, &pID);
if (!pID)
{
std::cout << "An error occured while getting the ID of the process.\n";
return "";
}
HANDLE Handle = CreateToolhelp32Snapshot(PROCESS_ALL_ACCESS, pID);
std::cout << pID << "\n";
//get module base name
char processName[MAX_PATH];
if (GetModuleBaseNameA(Handle, NULL, processName, sizeof(processName) / sizeof(char)))
{
CloseHandle(hwnd);
std::cout << "Succeed.\n";
return processName;
}
std::cout << "Failed. " << processName << "\n";
return "0xDEADBEEF";
}
the output I'm getting is: