0

So I tried to put together a window, but when I needed to name the window I told me. (Error: argument of type “const char*” is incompatible of type “LPCWSTR”) Programming for the CreateWindow method is underneath. Error should be in line 2.


hwnd = CreateWindow(
    "Engine_Winter_Name",
    "Winter Engine",
    WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
    GetSystemMetrics(SM_CXSCREEN)/2 - WIDTH/2,
    GetSystemMetrics(SM_CYSCREEN)/2 - HEIGHT/2,
    WIDTH,
    HEIGHT,
    (HWND)NULL,
    (HMENU)NULL,
    hInstance,
    (LPVOID*)NULL);

if (!hwnd)
    return false;

ShowWindow(hwnd, nCmdShow);

return true;

All help is more than welcome! Thanks in advance.

10emil10
  • 11
  • 4

2 Answers2

0

You need a wide string. Prefix your strings with L.

hwnd = CreateWindow(
    L"Engine_Winter_Name",
    L"Winter Engine",
2501
  • 25,460
  • 4
  • 47
  • 87
0

You're compiling with UNICODE defined, which means that e.g. the CreateWindow macro maps to CreateWindowW, which expects wide character (wchar_t-based) arguments:

hwnd = CreateWindow(
    L"Engine_Winter_Name",
    L"Winter Engine",
    WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
    GetSystemMetrics(SM_CXSCREEN)/2 - WIDTH/2,
    GetSystemMetrics(SM_CYSCREEN)/2 - HEIGHT/2,
    WIDTH,
    HEIGHT,
    HWND(),
    HMENU(),
    hInstance,
    nullptr);

if (!hwnd)
    return false;

ShowWindow(hwnd, nCmdShow);

For modern Windows desktop programming it's generally best to use the Unicode based API, as you're doing.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331