首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不明白这个错误(LPCWSTR)

我不明白这个错误(LPCWSTR)
EN

Stack Overflow用户
提问于 2015-08-18 14:12:00
回答 2查看 2K关注 0票数 0

嗨,我正在C++中为一个植物和僵尸训练师编写代码,只有当我试图启动它时,它失败了,这个错误:

错误:无法将参数“2”的“LPCWSTR {aka const wchar_t*}”转换为“LPCSTR {aka const char*}”,将其转换为“HWND__* FindWindowA(LPCSTR,LPCSTR)”

这是我的密码:

代码语言:javascript
复制
#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;
}

我发现这很难解决,所以我真的很感激谁能回答我的问题

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-18 14:15:29

不要使用FindWindowA(0, Game);,而是使用FindWindowW(0, Game);,或者简单地使用FindWindow

FindWindowA接受错误LPCSTR参数,您将传递LPCWSTR

票数 5
EN

Stack Overflow用户

发布于 2015-08-18 14:37:24

您的问题是,windows的通常有两种味道:

1) Ansi/ as (旧式),它使用char作为字符- API函数的基本类型,以A结尾-使用LPSTRLPCSTR

2) Unicode (本机),它使用wchar_t作为字符的基本类型- API函数以W结尾-使用LPWSTRLPCWSTR

您必须决定在批准参数类型中使用哪一种。您可以通过使用API的“中性”版本来避免其中的许多问题:这些API在名称末尾缺少AW,而且是宏的,根据宏UNICODE的定义,这些宏将被定义为实际的API之一。

中性版本使用宏的TCHARLPTSTRLPCTSTR。您应该包括tchar.h,它为您提供了一个用于操作以0结尾的TSTR数据的API。

有很多关于这个话题的信息可以通过googling找到。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32074871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档