handmade.network » Forums » Day 005 - WNDCLASS Errors
kurorah
1 posts
#14072 Day 005 - WNDCLASS Errors
9 months ago Edited by kurorah on Jan. 22, 2018, 7:52 a.m. Reason: Initial post

Whenever I try to use the following line from Casey's code I get multiple compile errors:
1
WNDCLASS WindowClass = {};

When defining:
1
WindowClass.lpszClassName = "GameWindowClass";
the compiler complains about type of the string not being wide unless prefixed with L. RegisterClassA(&WindowClass) is also refused due to type incompatibility with WNDCLASS.
Redefining WNDCLASS as WNDCLASSA allows it to compile but the window title is using Chinese characters?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
WNDCLASS WindowClass = {}; // OR WNDCLASSA

WindowClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
WindowClass.lpfnWndProc = Win32MainWindowCallback;
WindowClass.hInstance = Instance;
//WindowClass.hIcon;
WindowClass.lpszClassName = "GameWindowClass";

if(RegisterClassA(&WindowClass))
{
	HWND Window =
		CreateWindowExA(
			0,
			WindowClass.lpszClassName,
			"Game",
			WS_OVERLAPPEDWINDOW|WS_VISIBLE,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			0,
			0,
			Instance,
			0);
}
mmozeiko
Mārtiņš Možeiko
1811 posts / 1 project
#14073 Day 005 - WNDCLASS Errors
9 months ago Edited by Mārtiņš Možeiko on Jan. 22, 2018, 8:13 a.m.

Are you using Visual Studio project to compile not build.bat? If so then go to project settings and "Character Set" to "Not Set" (or "Use Multi-Byte Character Set"). Then windows headers will automatically use A functions and types.

Otherwise you need to change all Windows API functions and types to have A suffix in cases where they are either A or W.

When default VS project is created it is using "Unicode Character Set", but Casey's build.bat file expects it to not be set, that's why code for him compiles.