if ((WCHAR*)procName == procEntry32.szExeFile)
This is what I have, i've been told to use "strcmp" but it never seems to work. Could someone explain why? Or give me another solution?
bool attachProc(char* procName)
{
PROCESSENTRY32 procEntry32;
//_bstr_t procEntry32Char(procEntry32);
// defining the size for populating it
procEntry32.dwSize = sizeof(PROCESSENTRY32);
//getting the list of all the processes
auto hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
std::cout << procEntry32.szExeFile;
if (hProcSnap == INVALID_HANDLE_VALUE)
{
std::cout << "Failed To Take Snapshot Of Processes!" << std::endl;
return false;
}
Process32First(hProcSnap, &procEntry32);
while (Process32Next(hProcSnap, &procEntry32))
{
std::wcout << "Proc: " << procEntry32.szExeFile << std::endl;
int correct = (procEntry32.szExeFile == (WCHAR*)procName);
if (correct == 1)
{
//std::cout << "\nThe Program Was Found!\n";
}
else {
//std::cout << "\nThe Program Was Not Found!\n";
}
std::cout << ((WCHAR*)procName == procEntry32.szExeFile);
std::cout << "\nBoth:\n" << (WCHAR*)procName << "\n" << procEntry32.szExeFile << "\n\n";
if ((WCHAR*)procName == procEntry32.szExeFile)
{
std::cout << "Found Process " << procEntry32.szExeFile << " with process ID: " << procEntry32.th32ProcessID << std::endl;
hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procEntry32.th32ProcessID);
pID = procEntry32.th32ProcessID;
if (hProc == NULL)
{
std::cout << "Failed getting handle to process." << std::endl;
}
CloseHandle(hProcSnap);
return true;
}
}
std::cout << procEntry32.szExeFile;
std::cout << "Couldn't find " << procName << " in the process snapshot!" << std::endl;
CloseHandle(hProcSnap);
return false;
}
Here's the rest of the function, I'm a beginner so sorry for bad practices!