I have followed several tutorials, and am attempting to make a basic C++ game, starting with getting the window running.
When I try to run my code, I get a series of errors regarding the type of string, and no matter which tutorial I follow, I end up with similar errors.
I have tried including UNICODE
, messing with basically every type of string declaration I could find, and it still doesn't work.
Overall, I am just very confused on how the Windows API handles strings, and why the type of string even matters.
Attached is my Window
's constructor, which results in this error:
window.cpp:25:30: error: cannot convert 'const wchar_t*' to 'LPCSTR'
> {aka 'const char*'} in assignment 25 | wndClass.lpszClassName =
> CLASS_NAME;
Window::Window()
: m_hInstance(GetModuleHandle(nullptr))
{
const wchar_t* CLASS_NAME = L"Jacob's Window Class";
WNDCLASS wndClass = {};
wndClass.lpszClassName = CLASS_NAME;
wndClass.hInstance = m_hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.lpfnWndProc = nullptr; // Will update this later once I write it
RegisterClass(&wndClass);
DWORD style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
int width = 640;
int height = 480;
RECT rect;
rect.left = 250;
rect.top = 250;
rect.right = rect.left + width;
rect.bottom = rect.top + height;
AdjustWindowRect(&rect, style, false);
m_hWnd = CreateWindowEx(
0,
CLASS_NAME,
L"Title",
style,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
m_hInstance,
NULL
);
ShowWindow(m_hWnd, SW_SHOW);
}