simple windows app

i tried to making simple windows app with this 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
#include <iostream>
#include <windows.h>
using namespace std;

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

int WINAPI WinMain (HINSTANCE h_ins, HINSTANCE h_prev, LPSTR lp_cmd, int shw_cmd) {
	WNDCLASSEX wnd;
	static LPCTSTR wnd_name = L"Win App";
	HWND h_wnd;
	MSG msg;
	wnd.cbSize = sizeof (WNDCLASSEX);
	wnd.style = CS_HREDRAW | CS_VREDRAW;
	wnd.lpfnWndProc = WindowProc;
	wnd.cbClsExtra = 0;
	wnd.cbWndExtra = 0;
	wnd.hInstance = h_ins;
	wnd.hIcon = LoadIcon (0, IDI_APPLICATION);
	wnd.hCursor = LoadCursor (0, IDC_ARROW);
	wnd.hbrBackground = static_cast <HBRUSH> (GetStockObject(GRAY_BRUSH));
	wnd.lpszMenuName = 0;
	wnd.lpszClassName = wnd_name;
	wnd.hIconSm = 0;

	if (!RegisterClassEx (&wnd))
		return 0;
	h_wnd = CreateWindow (
		wnd_name,
		L"Windows example",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		0,
		0,
		h_ins,
		0
		);
	ShowWindow (h_wnd, shw_cmd);
	UpdateWindow (h_wnd);

	while (GetMessage (&msg, 0, 0, 0)) {
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}
	return static_cast <int> (msg.wParam);
}


but i got an error, why? i don't understand these errors

Error 1 error LNK2019: unresolved external symbol "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z) referenced in function _WinMain@16 test_code.obj C_test

Error 2 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib C_test

Error 3 fatal error LNK1120: 2 unresolved externals C:\Documents and Settings\ASUS\My Documents\Visual Studio 2008\Projects\C_test\Debug\C_test.exe 1 C_test

closed account (DSLq5Di1)
Where is WindowProc() defined? http://msdn.microsoft.com/en-us/library/ms633570

.. and are you sure you've created a Windows project? Check properties->Linker->System->SubSystem.
i defined windowproc() but it still error. where should i check this?

properties->Linker->System->SubSystem.
WindowProc() implementation is missing ...
You most likely create a console project, delete it and learn to use Visual Studio templates if you want to make a GUI application, it is not hard at all, just 2 or 3 mouse clicks and you have a working GUI program.
Is that all of the code you've written Chip?

If there's more, we are more likely to be able to help once you post it.
Last edited on
The errors are literally saying that the linker does not know what to do with the callback function "WindowProc()". The phrase "unresolved external symbol" generally means that the function is part of, or uses part of a component defined in another file, the only two DLL's you are using right now are "User32.DLL" and "Kernel32.DLL". A program running in user space will have those two libraries linked to it automatically.

Did you do something silly like define "WindowProc()" in a seperate header or cpp file that does not have "windows.h" included?
i'm sorry, guys... i just copy the wrong version of windowproc() from msdn web. so when i paste it i didn't know that the name was winWindowProc() (forgot the name) as i declare WindowProc() an not winWindowProc(). that's why i thought i have it defined. i just know it yesterday... my bad... :D i have it work after all... feels incredible (my 1st gui windows)... :))
Topic archived. No new replies allowed.