所以,我有这样的代码:
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...)上遇到错误。行,我完全不知道为什么,我已经尝试改变数据类型,看看这是不是问题所在,但似乎没有什么能解决它。
有什么建议吗?
发布于 2020-04-19 01:45:12
void targetProcessFinder(wchar_t targetProcess)
如果要传递单个wchar_t,则需要传递一个wchar_t*
_wcsicmp(entry.szExeFile, targetProcess)
如果您使用_MBCS编译器标志进行编译,那么PROCESS_ENTRY32.szExeFile是一个常规的字符数组,而不是wchar_t数组,在这种情况下,您需要将项目的字符集转换为Unicode。
https://stackoverflow.com/questions/50147297
复制相似问题