DWORD MainWindow::processNameToId()
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe))
{
return 0;
}
while (Process32Next(hSnapshot, &pe))
{
WCHAR x[260] = L"DNF.exe";
if (strcmp((char *)pe.szExeFile, (char *)x) == 0)
{
return pe.th32ProcessID;
}
}
return 0;
}
------解决思路----------------------
很明显,你的值是宽字符,不能用strcmp比较,改在wcscmp就行了.