Вот мои ошибки:
Код: Выделить всё
'TH32CS_PROCESS': undeclared identifier: Line 11
'': cannot convert from 'WCHAR [260]' to 'std::string' Line 20
identifier "TH32CS_PROCESS" is undefined Line 22
Код: Выделить всё
#include
#include
#include
#include
#include
#include
#include // Include for string conversion
namespace fs = std::filesystem;
// Function to convert WCHAR to std::string
std::string WCharToString(const WCHAR* wcharStr) {
// Convert WCHAR* to std::string
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wcharStr, -1, NULL, 0, NULL, NULL);
std::string str(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, wcharStr, -1, &str[0], size_needed, NULL, NULL);
return str;
}
// Function to get the process ID by name
DWORD GetProcessIdByName(const std::string& processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_PROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe)) {
do {
// Convert WCHAR to std::string for comparison
std::string processNameStr = WCharToString(pe.szExeFile);
if (processNameStr == processName) {
CloseHandle(hSnapshot);
return pe.th32ProcessID;
}
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return 0;
}
// Function to inject DLL into a process
void InjectDLL(DWORD processID, const std::string& dllPath) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
if (!hProcess) {
std::cerr
Подробнее здесь: [url]https://stackoverflow.com/questions/79129788/th32cs-process-undelcared-identifier[/url]