undefined defaults... maybe?

Im just trying to implement an example from the book,I know the basics of C++ but I see them using all these undefined constants... or maybe macros... anyway the compiler shows me errors about things like WndProc and rc, claiming they are undefined identifiers. what is wrong?

here is code:
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{
	UNREFERENCED_PARAMETER(prevInstance);
	UNREFERENCED_PARAMETER(cmdLine);

	WNDCLASSEX wndClass={0};
	wndClass.cbSize=sizeof(WNDCLASSEX);
	wndClass.style=CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc=WndProc;
	wndClass.hInstance=hInstance;
	wndClass.hCursor=LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1);
	wndClass.lpszMenuName=NULL;
	wndClass.lpszClassName="DX11BookWindowClass";

	if(!RegisterClassEx(&wndClass))
		return -1;

	RECT rc {0,0,640,480};
	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);

	HWND hwnd = CreateWindow("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

	if(hwnd)
		return -1;

	ShowWindow(hwnd, cmdShow);

	MSG msg = {0};

	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg,0,0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return static_cast<int>(msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT paintStruct;
	HDC hDC;

	switch(message)
	{
		case WM_PAINT:
			hDC= BeginPaint(hwnd,&paintStruct);
			EndPaint(hwnd,&paintStruct);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}
I see them using all these undefined constants... or maybe macros..
You shouldn't see anything like that. Can you post the actual compiler errors verbatim please.
i found out that there was 1 thing wrong, a missing = on line 23 adding that the code is:

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{
	UNREFERENCED_PARAMETER(prevInstance);
	UNREFERENCED_PARAMETER(cmdLine);

	WNDCLASSEX wndClass={0};
	wndClass.cbSize=sizeof(WNDCLASSEX);
	wndClass.style=CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc=WndProc;
	wndClass.hInstance=hInstance;
	wndClass.hCursor=LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1);
	wndClass.lpszMenuName=NULL;
	wndClass.lpszClassName="DX11BookWindowClass";

	if(!RegisterClassEx(&wndClass))
		return -1;

	RECT rc = {0,0,640,480};
	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);

	HWND hwnd = CreateWindow("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

	if(hwnd)
		return -1;

	ShowWindow(hwnd, cmdShow);

	MSG msg = {0};

	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg,0,0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return static_cast<int>(msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT paintStruct;
	HDC hDC;

	switch(message)
	{
		case WM_PAINT:
			hDC= BeginPaint(hwnd,&paintStruct);
			EndPaint(hwnd,&paintStruct);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}



however it does not execute correctly and generates these errors:

'BlankWindow.exe': Loaded 'C:\Users\Preston\Desktop\stuff\Green\BlankWindow\Debug\BlankWindow.exe', Symbols loaded.
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'BlankWindow.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
The program '[2520] BlankWindow.exe: Native' has exited with code -1 (0xffffffff).
Last edited on
The app isn't working because you close it before it gets going with
1
2
	if(hwnd)
		return -1;

You probably mean
1
2
	if(hwnd == NULL)
		return -1;


The warnings you've posted are not compile time messages. They're runtime messages issued by the debugger.
http://www.cplusplus.com/forum/windows/63103/#msg342012
Last edited on
sorry if i wasn't clear on what the errors were, but you were right i didn't notice that the book code actualy said:

1
2
if(!hwnd)
		return -1;


ty so much for the help, but one last thing, the book im learning from is begining direct x 11 game programming, but after seeing this code I feel a bit overwhelmed by Win32 programming and the like. If i were looking for a book on the subject of... this stuff, as in GUI based software and programs made from C++, what... key words should I look with?
Using a native GUI API is always tricky. A GUI app communicates with the GUI runtime using messages. Without a system for dealing with these messages, you very quickly find yourself with spaghetti code.

The solution is to use a GUI framework that handles all the mundane detail for you, freeing you to focus on your stuff. Common ones are:
http://www.libsdl.org/
http://www.sfml-dev.org/

I thought this was interesting, but have never used it.
http://www.antisphere.com/Wiki/tools:anttweakbar
Topic archived. No new replies allowed.