嗨,我正在C++中为一个植物和僵尸训练师编写代码,只有当我试图启动它时,它失败了,这个错误:
错误:无法将参数“2”的“LPCWSTR {aka const wchar_t*}”转换为“LPCSTR {aka const char*}”,将其转换为“HWND__* FindWindowA(LPCSTR,LPCSTR)”
这是我的密码:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
system("color 0A");//change the colour of the text
cout << "PlantsVsZombies Trainer voor game of the year edition(gemaakt door Pjotr Slooff)" << endl;//display some (dutch) text
cout << "Open PlantsVsZombies en druk dan op enter" << endl;
system("Pause");//wait for the user to press enter
LPCWSTR Game = L"Plants vs. Zombies";
HWND hwnd = FindWindowA(0, Game);
if (hwnd == 0)
{
cout << "PlantsVsZombies is niet gevonden open het en probeer het dan opnieuw" << endl;
system("Pause");
}
else
{
DWORD process_ID;
GetWindowThreadProcessId(hwnd, &process_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_ID);
cout << "PlantsVsZombies is gevonden! Happy Hacking :D" << endl;
system("Pause");
cout << "Typ 1 voor Zon Cheat" << endl;
cout << "Typ: ";
int Option;
cin >> Option;
if (Option > 1)
{
cout << "Er is maar 1 optie" << endl;
system("Pause");
}
if (Option == 1)
{
cout << "Hoeveel Zon wil je?" << endl;
cout << "Typ: ";
int Zon;
cin >> Zon;
DWORD newdatasize = sizeof(Zon);
if (WriteProcessMemory(hProcess, (LPVOID)00005560, &Zon, newdatasize, NULL))
{
cout << "De Zon is toegevoegd" << endl;
system("Pause");
}
else
{
cout << "Er was een error tijdens het toevoegen van de Zon" << endl;
system("Pause");
}
}
}
main();
return 0;
}我发现这很难解决,所以我真的很感激谁能回答我的问题
发布于 2015-08-18 14:15:29
不要使用FindWindowA(0, Game);,而是使用FindWindowW(0, Game);,或者简单地使用FindWindow
FindWindowA接受错误LPCSTR参数,您将传递LPCWSTR。
发布于 2015-08-18 14:37:24
您的问题是,windows的通常有两种味道:
1) Ansi/ as (旧式),它使用char作为字符- API函数的基本类型,以A结尾-使用LPSTR和LPCSTR。
2) Unicode (本机),它使用wchar_t作为字符的基本类型- API函数以W结尾-使用LPWSTR和LPCWSTR。
您必须决定在批准参数类型中使用哪一种。您可以通过使用API的“中性”版本来避免其中的许多问题:这些API在名称末尾缺少A或W,而且是宏的,根据宏UNICODE的定义,这些宏将被定义为实际的API之一。
中性版本使用宏的TCHAR、LPTSTR和LPCTSTR。您应该包括tchar.h,它为您提供了一个用于操作以0结尾的TSTR数据的API。
有很多关于这个话题的信息可以通过googling找到。
https://stackoverflow.com/questions/32074871
复制相似问题