Linking error with CreateWindow()

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
// CheckersGame.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "CheckersGame.h"


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR    lpCmdLine, int  nCmdShow)
{ WNDCLASSEX windowdesc;
    TCHAR Name[] = _T("CheckersGame");
    
    windowdesc.cbSize = sizeof(WNDCLASSEX);
	windowdesc.lpszClassName = Name;
    windowdesc.style          = CS_HREDRAW | CS_VREDRAW;
    windowdesc.lpfnWndProc    = WndProc;
    windowdesc.cbClsExtra     = 0;
    windowdesc.cbWndExtra     = 0;
    windowdesc.hInstance      = hInstance;
    windowdesc.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    windowdesc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    windowdesc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    windowdesc.lpszMenuName   = NULL;
    windowdesc.hIconSm        = LoadIcon(windowdesc.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	HWND WindObj = CreateWindow(Name, Name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL);
	return 0;
}





/*Errors: error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function _wWinMain@16
1>C:\Users\alex\documents\visual studio 2010\Projects\CheckersGame\Debug\CheckersGame.exe : fatal error LNK1120: 1 unresolved externals.*/ 

// What am i doing wrong here? 
The linker is not finding your WndProc() function. Where do you have it?
I declared it... But do I need to specify its implementation????
Last edited on
Yes, the window procedure is the most important part of a Windows program. Even if its as simple as this...

1
2
3
4
5
6
7
8
9
10
11
LRESULT CALLBACK WndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
 if(msg==WM_DESTROY)
 {
    PostQuitMessage(0);
    return 0L;
 } 

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}


And it looks like you forgot to register the window class.
Last edited on
Topic archived. No new replies allowed.