newbie winapi compiling error

hello guys im a newbie i dunno what is wrong with this code?
can you help me guys figure it out?

error C2440

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
66
67
68
#include <windows.h>

LPCTSTR  clsName = L"renClass";
LPCTSTR  WndName = L"RenWindow";

LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,LPARAM lParam,WPARAM wParam);

int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lCmdLine,
				   int nCmdShow)
{
	MSG   msg;
	HWND hWnd;
	WNDCLASSEX renWin;

	renWin.cbSize          = sizeof(WNDCLASSEX);
	renWin.style           = CS_HREDRAW | CS_VREDRAW;
	renWin.cbClsExtra      = 0;
	renWin.cbWndExtra      = 0;
	renWin.lpfnWndProc     = WndProc;
	renWin.hInstance       = hInstance;
	renWin.hIcon           = LoadIcon(NULL,IDI_APPLICATION);
	renWin.hIconSm         = LoadIcon(NULL,IDI_APPLICATION);
	renWin.hCursor         = LoadCursor(NULL,IDC_ARROW);
	renWin.hbrBackground   = (HBRUSH)GetStockObject(GRAY_BRUSH);
	renWin.lpszMenuName    = NULL;
	renWin.lpszClassName   = clsName;

	RegisterClassEx(&renWin);

	hWnd = CreateWindow(clsName,
		                WndName,
						WS_OVERLAPPEDWINDOW,
						CW_USEDEFAULT,
						CW_USEDEFAULT,
						CW_USEDEFAULT,
						CW_USEDEFAULT,
						NULL,
						NULL,
						hInstance,
					    NULL);
	if(!hWnd)
		return 0;

	ShowWindow(hWnd,SW_SHOWNORMAL);
	
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	};

	return msg.wParam;
};

LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,LPARAM lParam,WPARAM wParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;
	default:
		return DefWindowProc(hWnd,msg,lParam,wParam);
	}
	return 0;
};


here is the error message:


1>------ Build started: Project: windowsProg_one, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>d:\programming\windowsprog_one\main.cpp(21) : error C2440: '=' : cannot convert from 'LRESULT (__stdcall *)(HWND,UINT,LPARAM,WPARAM)' to 'WNDPROC'
1>        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
1>d:\programming\windowsprog_one\main.cpp(54) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
1>Build log was saved at "file://d:\PROGRAMMING\windowsProg_one\Debug\BuildLog.htm"
1>windowsProg_one - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Last edited on
closed account (z05DSL3A)
Try changing line 21 to renWin.lpfnWndProc = (WNDPROC) WndProc;
Read the error message !

"This conversion requires a reinterpret_cast, a C-style cast or function-style cast"

It can't be clearer .
Last edited on
settle down george, Read the post title!
Topic archived. No new replies allowed.