I am trying to get the procid of a process using the name of the process. The errors are talking about procEntry.szExeFile. However, I am getting the errors:
[{
"owner": "C/C++",
"code": "167",
"severity": 8,
"message": "argument of type \"WCHAR *\" is incompatible with parameter of type \"const char *\"",
"source": "C/C++",
"startLineNumber": 17,
"startColumn": 17,
"endLineNumber": 17,
"endColumn": 26
},{
"owner": "C/C++",
"code": "167",
"severity": 8,
"message": "argument of type \"WCHAR *\" is incompatible with parameter of type \"const char *\"",
"source": "C/C++",
"startLineNumber": 24,
"startColumn": 21,
"endLineNumber": 24,
"endColumn": 30
}]
Is there another way to get the process ID? I have tried reinstalling c++ libraries. I have also tried converting it but that didn't work either. Here is the code I am using:
#include <stdlib.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <TlHelp32.h>
// Get process id from name
DWORD GetProcId(const char* procName)
{
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (hSnap == INVALID_HANDLE_VALUE)
return 0;
Process32First(hSnap, &procEntry);
if (!strcmp(procEntry.szExeFile, procName))
{
CloseHandle(hSnap);
return procEntry.th32ProcessID;
}
while (Process32Next(hSnap, &procEntry))
{
if (!strcmp(procEntry.szExeFile, procName))
{
CloseHandle(hSnap);
return procEntry.th32ProcessID;
}
}
CloseHandle(hSnap);
return 0;
}
int main()
{
// Get process id from name
DWORD procId = GetProcId("csgo.exe");
if (!procId)
{
std::cout << "Could not find process" << std::endl;
return 0;
}
// wait for key press
std::cout << "Press any key to continue" << std::endl;
std::getchar();
return 0;
}