无法将 char[9] 转换为 char*
Can't convert char[9] to char*
我是游戏黑客的新手,我是从学习教程开始的,该教程提供了源代码。了解它的作用后,我尝试编译,出现了 3 个相同的错误:
Can't convert char[9] to char* (Error n. C2664)
错误是指变量 ProcessName
和 ModuleName
。
即使我有很好的 C++ 基础知识,我在使用指针时也总是遇到困难。
对错误感兴趣的函数是这两个:
bool AttachProcess(char *ProcessName) {
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
const WCHAR* procNameChar;
int nChars = MultiByteToWideChar(CP_ACP, 0, ProcessName, -1, NULL, 0);
procNameChar = new WCHAR[nChars];
MultiByteToWideChar(CP_ACP, 0, ProcessName, -1, (LPWSTR)procNameChar, nChars);
do
if (!wcscmp(procEntry.szExeFile, procNameChar))
{
this->dwPID = procEntry.th32ProcessID;
CloseHandle(hPID);
this->hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->dwPID);
return true;
}
while (Process32Next(hPID, &procEntry));
CloseHandle(hPID);
return false;
}
MODULEENTRY32 GetModule(char* ModuleName)
{
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(mEntry);
const WCHAR* modNameChar;
int nChars = MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, NULL, 0);
modNameChar = new WCHAR[nChars];
MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, (LPWSTR)modNameChar, nChars);
do
if (!wcscmp(mEntry.szModule, modNameChar))
{
CloseHandle(hModule);
return mEntry;
}
while (Module32Next(hModule, &mEntry));
CloseHandle(hModule);
mEntry.modBaseAddr = 0x0;
return mEntry;
}
我在这里回忆那些功能:
MemoryManager()
{
this->hProcess = NULL;
this->dwPID = NULL;
try {
if (!AttachProcess("csgo.exe")) throw 1;
this->ClientDLL = GetModule("client.dll");
this->EngineDLL = GetModule("engine.dll");
//and so on
我投了“csgo.exe”、“engine.dll”和“client.dll”:
if (!AttachProcess(const_cast<char*>("csgo.exe"))) throw 1;
this->ClientDLL = GetModule(const_cast<char*>("client.dll"));
this->EngineDLL = GetModule(const_cast<char*>("engine.dll"));
发生错误是因为您试图将字符串文字 (const char[]
) 传递给需要指向非常量字符数组 (char *
) 的指针的函数。
因为你从不修改ProcessName
的内容你应该改变
bool AttachProcess(char *ProcessName)
到
// VVVVV
bool AttachProcess(const char *ProcessName)
我是游戏黑客的新手,我是从学习教程开始的,该教程提供了源代码。了解它的作用后,我尝试编译,出现了 3 个相同的错误:
Can't convert char[9] to char* (Error n. C2664)
错误是指变量 ProcessName
和 ModuleName
。
即使我有很好的 C++ 基础知识,我在使用指针时也总是遇到困难。
对错误感兴趣的函数是这两个:
bool AttachProcess(char *ProcessName) {
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
const WCHAR* procNameChar;
int nChars = MultiByteToWideChar(CP_ACP, 0, ProcessName, -1, NULL, 0);
procNameChar = new WCHAR[nChars];
MultiByteToWideChar(CP_ACP, 0, ProcessName, -1, (LPWSTR)procNameChar, nChars);
do
if (!wcscmp(procEntry.szExeFile, procNameChar))
{
this->dwPID = procEntry.th32ProcessID;
CloseHandle(hPID);
this->hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->dwPID);
return true;
}
while (Process32Next(hPID, &procEntry));
CloseHandle(hPID);
return false;
}
MODULEENTRY32 GetModule(char* ModuleName)
{
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(mEntry);
const WCHAR* modNameChar;
int nChars = MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, NULL, 0);
modNameChar = new WCHAR[nChars];
MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, (LPWSTR)modNameChar, nChars);
do
if (!wcscmp(mEntry.szModule, modNameChar))
{
CloseHandle(hModule);
return mEntry;
}
while (Module32Next(hModule, &mEntry));
CloseHandle(hModule);
mEntry.modBaseAddr = 0x0;
return mEntry;
}
我在这里回忆那些功能:
MemoryManager()
{
this->hProcess = NULL;
this->dwPID = NULL;
try {
if (!AttachProcess("csgo.exe")) throw 1;
this->ClientDLL = GetModule("client.dll");
this->EngineDLL = GetModule("engine.dll");
//and so on
我投了“csgo.exe”、“engine.dll”和“client.dll”:
if (!AttachProcess(const_cast<char*>("csgo.exe"))) throw 1;
this->ClientDLL = GetModule(const_cast<char*>("client.dll"));
this->EngineDLL = GetModule(const_cast<char*>("engine.dll"));
发生错误是因为您试图将字符串文字 (const char[]
) 传递给需要指向非常量字符数组 (char *
) 的指针的函数。
因为你从不修改ProcessName
的内容你应该改变
bool AttachProcess(char *ProcessName)
到
// VVVVV
bool AttachProcess(const char *ProcessName)