When I use the following function as isRunning("example.exe"); it always returns 0 no matter if the process is running or not.
I tried making it std::cout << pe.szExeFile; in the do-while loop and it outputs all the processes in the same format as I am trying to pass the function.
The project is multi-byte character set, in case that makes a difference.
bool isRunning(CHAR process_[]) { HANDLE pss = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); PROCESSENTRY32 pe = { 0 }; pe.dwSize = sizeof(pe); if (Process32First(pss, &pe)) { do { if (pe.szExeFile == process_) // if(!strcmp(pe.szExeFile, process_)) is the correct line here return true; // If you use this remember to close the handle here too with CloseHandle(pss); } while (Process32Next(pss, &pe)); } CloseHandle(pss); return false; } Can't seem to find my mistake. Thanks for your time.
char*not the actual name of the process, you'll need to usestrcmppssin the case of a match. I don't know if this is intended. It very much looks like a leak. You should either make sure that every code path performs clean-up manually, or use a scope guard.