c++ - 我不明白这个错误 (LPCWSTR)

标签 c++

您好,我正在用 C++ 为植物大战僵尸训练器编写代码,只有当我尝试启动它时,它因以下错误而失败:

error: cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}' for argument '2' to '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;
}

我觉得这很烦人,我无法解决它,所以我真的很感激谁能回答我的问题

最佳答案

代替 FindWindowA(0, Game); 使用 FindWindowW(0, Game);,或者简单地 FindWindow

FindWindowA 错误地接受 LPCSTR 参数,而您正在传递 LPCWSTR

关于c++ - 我不明白这个错误 (LPCWSTR),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074871/

相关文章:

c++ - 在 3D 矩阵上模拟基本扩散的最简单方法?

C++生成0到100,000之间的随机数

c++ - 如果包含 map 的静态库与可执行和动态库链接,静态 map (变量)会被多次释放吗?

c++ - 准确计算 C++ 程序使用的内存

c++ - 枚举C++中的所有组合

c++ - 如何将非英语字符串写入文件并使用 C++ 从该文件中读取?

c++ - 如何减少 priority_queue<PI, vector<PI> ,greater<PI>> 中特定边的键,试图实现 prim 的算法?

c++ - 放置新的覆盖现有对象

C++ Tensorflow lite,某些函数的 undefined reference

c++ - 如何通过我自己的函数传递boost::asio::yield_context?