HANDLE GetHandleByProcessName(const char* processName, DWORD dwAccessRights)
{
DWORD pID = NULL;
HANDLE hProcess = INVALID_HANDLE_VALUE;
HANDLE ss = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (ss != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
do
{
if (!strcmp(pe.szExeFile, processName))
{
pID = pe.th32ProcessID;
hProcess = OpenProcess(dwAccessRights, false, pID);
}
} while (Process32Next(ss, &pe));
CloseHandle(ss);
}
return hProcess;
}
这是我用来返回进程句柄的代码。
if (!strcmp(pe.szExeFile, processName))
{
这是导致错误(E0167)和(C2664)错误的原因,特别是pe.szExeFile
字段。
如何将WCHAR [260]
转换为const char*
,使其可以正常工作?