[比较ProcessEntry32.szExeFile与用户输入的数据时,C ++ _wcsicmp代码未编译

问题描述 投票:0回答:1

所以,我有这个代码:

using namespace std;
void targetProcessFinder(wchar_t targetProcess)
{

PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);

HANDLE processSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

if(Process32First(processSnapshot, &entry) == TRUE)
    {
        while(Process32Next(processSnapshot, &entry) == TRUE)
            {
                if (_wcsicmp(entry.szExeFile, targetProcess) == 0)
                {
                    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
                    int processID = entry.th32ProcessID;

                    CloseHandle(hProcess);
                }
            }
    }
}

int main()
{
    wchar_t targetProcess
    cin >> targetProcess;
    targetProcessFinder(targetProcess);
}

由于某种原因,我在if(_wcsicmp ...)行上遇到错误,而我完全不知道为什么,我尝试过更改数据类型以查看是否是问题所在,但似乎没有任何解决方法它。

有什么建议吗?

c++ process
1个回答
0
投票

void targetProcessFinder(wchar_t targetProcess)

您要传递一个wchar_t,您需要传递一个wchar_t *

_wcsicmp(entry.szExeFile, targetProcess)

如果使用_MBCS编译器标志进行编译,则PROCESS_ENTRY32.szExeFile是常规char数组,而不是wchar_t数组,在这种情况下,您需要将项目的字符集切换为Unicode。

© www.soinside.com 2019 - 2024. All rights reserved.