-2

I'm wondering why I cannot set the name. This is the error:

image

It doesn't even let me assign a char.

#include <windows.h>

LRESULT CALLBACK window_callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
    //create window class
    WNDCLASS window_class = {};
    window_class.style = CS_HREDRAW | CS_VREDRAW;
    window_class.lpszClassName = "Game Window Class";
    window_class.lpfnWndProc = window_callback;//callback
    
    //Register class

    //Create window
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Stella
  • 1
  • 3
  • [What does LPCWSTR stand for and how should it be handled?](https://stackoverflow.com/questions/2230758/what-does-lpcwstr-stand-for-and-how-should-it-be-handled-with) – Drew Dormann Sep 25 '22 at 23:09
  • All questions here should have all relevant information ***in the question itself as plain text***. Links can stop working at any time making questions meaningless. Code, data, or errors shown as images cannot be copy/pasted; or edited or compiled for further research and investigation. Can you [edit] this question, removing and replacing all links and images with all relevant information as plain text? All code must meet all requirements of a [mre]. You'll find many other questions here, with a [mre], in plain text. Please use them as an example for how your question should look. – Sam Varshavchik Sep 25 '22 at 23:10
  • Does this answer your question? [Cannot convert parameter from 'const char\[20\]' to 'LPCWSTR'](https://stackoverflow.com/questions/5481378/cannot-convert-parameter-from-const-char20-to-lpcwstr) – Raymond Chen Sep 26 '22 at 01:02

1 Answers1

1

WNDCLASS::lpszClassName is an LPCTSTR pointer, ie a const TCHAR* pointer. TCHAR maps to wchar_t when UNICODE is defined, otherwise it maps to char instead.

You are compiling your project with UNICODE defined, because lpszClassName is expecting a wide const wchar_t* pointer to a Unicode string, but you are giving it a (decayed) narrow const char* pointer to an ANSI string literal instead, hence the error.

You can either:

  • undefine UNICODE in your project settings.

  • prefix the string literal with L to make it a Unicode string:

    window_class.lpszClassName = L"Game Window Class";

  • wrap the string literal in the TEXT() macro:

    window_class.lpszClassName = TEXT("Game Window Class");

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770