trying to make a window in c++, errors with assigning strings, LPCSTR / LPCWSTR stuff

243 views Asked by At

iv'e been googling for hours, nothing seems to work. i'm not splitting my stuff into .h and .cpp because weird stuff happens for some reason, but that's beside the point

i am getting the following errors:
cannot convert 'const wchar_t [16]' to 'LPCSTR' {aka 'const char*'} in assignment gcc [59,24]
cannot convert 'const wchar_t [1]' to 'LPCSTR' {aka 'const char*'} in assignment gcc [60,23]
argument of type "const char " is incompatible with parameter of type "LPCWSTR" [68,54] cannot convert 'const wchar_t' to 'LPCSTR' {aka 'const char*'} 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

heres my tasks.json in case the problem is there somehow

{
    "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
            }
        }
    ]
}
1

There are 1 answers

1
Aerbon On

seems to be solved!

i'm still not sure exactly why this works now, but changing some of the api functions to the "W version" fixed it i had been trying this already but i guess some other stuff along the way must've also been fixed.

thanks for the help, rustyx.