我不明白这个错误(LPCWSTR)

时间:2015-08-18 14:12:01

标签: c++

您好我正在使用C ++编写植物大战僵尸训练师的代码,但是当我尝试启动它时,它失败并出现此错误:

  

错误:无法将'LPCWSTR {aka const wchar_t *}'转换为'LPCSTR {aka const char *}'以将参数'2'转换为'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;
}

我觉得这很无聊,我无法修复,所以我真的很感激谁能回答我的问题

2 个答案:

答案 0 :(得分:4)

而不是FindWindowA(0, Game);使用FindWindowW(0, Game);,或只是FindWindow

FindWindowA接受错误的LPCSTR参数,并且您正在传递LPCWSTR

答案 1 :(得分:2)

您的问题是 Windows API 通常有两种形式:

1) Ansi / Ascii (旧版)使用char作为角色的基本类型     - 以 A 结尾的API函数     - 使用LPSTRLPCSTR

2) Unicode (原生),使用wchar_t作为角色的基本类型     - 以 W 结尾的API函数     - 使用LPWSTRLPCWSTR

您必须决定使用适当的参数类型。 您可以使用API​​的“中性”版本来避免许多这些问题: 它们在名称的末尾缺少 A W ,并且是将被定义为实际API之一的宏 取决于宏UNICODE的定义。

中性版使用宏的TCHARLPTSTRLPCTSTR。 您应该包含 tchar.h ,它为您提供了一个用于处理0终止 TSTR 数据的API。

通过Google搜索可以找到有关此主题的大量信息。