-2

我已经在谷歌上搜索了几个小时,似乎没有任何效果。我不会将我的东西分成 .h 和 .cpp ,因为奇怪的东西出于某种原因会发生,但这不是重点

我收到以下错误:
无法将 'const wchar_t [16]' 转换为 'LPCSTR' {aka 'const char*'} in assignment gcc [59,24]
cannot convert 'const wchar_t [1]' to 'LPCSTR' { “const char”类型的赋值 gcc [60,23]
参数中的又名 'const char*'}与“LPCWSTR”类型的参数不兼容 [68,54] 无法将 'const wchar_t ' 转换为 'LPCSTR' {aka 'const字符*'} gcc [68,72]

#ifndef WINDOW_INCLUDED
#define WINDOW_INCLUDED

#define _UNICODE
#include <Windows.h>

class Window{
    public:
    Window();
    //intitialize window
    bool init();
    bool broadcast();
    //release window
    bool release();
    bool isRunning();
    //virtual events
    virtual void onCreate();
    virtual void onUpdate();
    virtual void onDestroy();
    ~Window();
    protected:
    HWND m_hwnd;
    bool m_is_running;
};

//i'm not splitting this into an h and cpp file lol

Window* window = nullptr;

Window::Window(){

}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
    switch(msg){
        case WM_CREATE:{
            window->onCreate();
            break;
        }
        case WM_DESTROY:{
            window->onDestroy();
            ::PostQuitMessage(0);
            break;
        }
        default:
            return ::DefWindowProc(hwnd,msg,wparam,lparam);
    }
    return NULL;
}
bool Window::init(){
    WNDCLASSEX wc;
    wc.cbClsExtra = NULL;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbWndExtra = NULL;
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
    wc.hInstance = NULL;
    wc.lpszClassName = L"GameWindowClass"; //ERROR HERE
    wc.lpszMenuName = L""; //ERROR HERE
    wc.style = NULL;
    wc.lpfnWndProc = &WndProc;
    if(!::RegisterClassEx(&wc))
        return false; //abort if registration fails
    //get window pointer
    if(!window)
        window = this;
    m_hwnd = ::CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,"GameWindowClass"/*ERROR HERE*/,L"kool gaem lul",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,1024,768,NULL,NULL,NULL,NULL);
    if(!m_hwnd)
        return false; //abort if window creation fails
    //show window
    ::ShowWindow(m_hwnd,SW_SHOW);
    ::UpdateWindow(m_hwnd);
    m_is_running = true;//we did it bois, window exists!
    return true; //all green, mission complete!
}
bool Window::broadcast(){
    MSG msg;
    while (::PeekMessage(&msg,NULL,0,0,PM_REMOVE)>0){//user-kun is giving us input, lets process it!
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    window->onUpdate();//update stuff
    Sleep(0); //give the computer a rest, hes a hard working boi.
    return true;
}
bool Window::release(){
    if(!::DestroyWindow(m_hwnd)) //destroy window
        return false; //abort case window is not destroyed
    return true;
}
bool Window::isRunning(){
    return m_is_running;
}
void Window::onDestroy(){
    m_is_running = false;//window is kill. no.
}
Window::~Window(){

}

#endif

这是我的tasks.json,以防问题出现

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\main_win32.exe",
                "-I",
                "${fileDirname}\\libraries",
                "-I",
                "${fileDirname}\\classes",
                "-I",
                "${fileDirname}\\lib_w32"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
4

1 回答 1

-1

似乎解决了!

我仍然不确定为什么现在这样有效,但是将一些 api 函数更改为“W 版本”修复了它我已经尝试过这个但我想沿途的其他一些东西也必须修复。

谢谢你的帮助,生锈的。

于 2020-09-09T18:28:46.087 回答