This isn't actually my code, but I need help right here. Since I'm new to coding, I don't know how to fix this problem.
bool GetProcessEntryByName(string name, PROCESSENTRY32* pe) {
auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE) {
cerr << "Tool helper cannot be created" << endl;
return false;
}
if (!Process32First(snapshot, pe)) {
cerr << "Tool helper cannot retrieve the first entry of process list" << endl;
return false;
}
do {
if (pe->szExeFile == name) {
snapshot ? CloseHandle(snapshot) : 0;
return true;
}
} while (Process32Next(snapshot, pe));
snapshot ? CloseHandle(snapshot) : 0;
return false;
}
And the error occurs at: if (pe->szExeFile == name)....
Output:
1>------ Rebuild All started: Project: EzExecV2, Configuration: Debug x64 ------
1>main.cpp
1>E:\Desktop\Coding\Test\main.cpp(45,28): error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\guiddef.h(192,15): message : could be 'bool operator ==(const GUID &,const GUID &)'
1>D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\random(2056,24): message : or 'bool std::operator ==(const std::bernoulli_distribution &,const std::bernoulli_distribution &)'
1>E:\Desktop\Coding\Test\main.cpp(45,28): message : or 'built-in C++ operator==(WCHAR [260], WCHAR [260])'
1>E:\Desktop\Coding\Test\main.cpp(45,28): message : while trying to match the argument list '(std::string, WCHAR [260])'
1>E:\Desktop\Coding\Test\main.cpp(106,24): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(106,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(111,27): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(111,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(133,23): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(133,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(137,24): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(137,9): warning C4309: 'argument': truncation of constant value
1>Done building project "Test.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I'm using Unicode Char Set
I don't know if there is a more detailed log for the build. If there is, tell me where I can find it.
You are compiling the project with Unicode, so Process32FirstW()
will be called instead of Process32First()
. Change your function to take wstring
as parameter or convert name
to wstring
before comparison:
std::wstring wName(name.begin(), name.end());
if (pe->szExeFile == wName) {
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments