Skip to main content
gamedev.net
🔒 Locked

LRESULT CALLBACK function

Started by wforl Jul 11, 2008 at 8:20 AM 3 replies 2.6k views
Original Post
wforl
wforl
Im int the middle of adjusting some code, and ive come across the following error, to which i dont know whats wrong. Can anyone help out.
Error	1	error C2440: '=' : cannot convert from 'LRESULT (__stdcall winApp::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'	d:\programming\my game\winapp.cpp	59


here is the declaration of that function , (ive removed most of the uneeded stuff)



class winApp
{
public:
	winApp(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP);
	virtual ~winApp();

	
	virtual void initMainWindow();
	virtual void initDirect3D();
	virtual int run();
	LRESULT CALLBACK msgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);


	

	
	
};



here is the definition

LRESULT CALLBACK winApp::msgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//removed code
}

and here is where the window is setup

void winApp::initMainWindow()
{
	WNDCLASS wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wc.lpfnWndProc   = &winApp::msgProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = mhAppInst;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = TEXT("D3DWndClassName");

	if( !RegisterClass(&wc) )
	{
		MessageBox(0, TEXT("RegisterClass FAILED"), 0, 0);
		PostQuitMessage(0);
	}

	mhMainWnd = CreateWindow(TEXT("D3DWndClassName"), TEXT("Guns and blood 'n' stuff"), 
		WS_POPUP | WS_BORDER | WS_VISIBLE , 
		(int)this->CentreOfScreen.x - (int)(this->GameWindowSize.x/2),			//position x
		(int)this->CentreOfScreen.y - (int)(this->GameWindowSize.y/2),			//position y
		(int)this->GameWindowSize.x,			//size x
		(int)this->GameWindowSize.y,			//size y
		NULL, NULL, mhAppInst, 0); 

	if( !mhMainWnd )
	{
		MessageBox(0, TEXT("CreateWindow FAILED"), 0, 0);
		PostQuitMessage(0);
	}

	ShowWindow(mhMainWnd, SW_SHOW);
	UpdateWindow(mhMainWnd);

}

Evil Steve
Evil Steve
You can't have your window proc as a class member function. There's a bunch of ways around it, Googling "Window proc in a class" should give loads of hits. This is the way I use (Appologies for the terrible site :P)

EDIT: Bah, too slow [smile]
MJP
MJP
Using GWL_USERDATA to redirect a function call? Kid's stuff! Real men use a ATL-style thunk!

DISCLAIMER: MJP does not actually advocate using this method, he is just kidding around to try to make Evil Steve look bad.
Evil Steve
Evil Steve
Quote:
Original post by MJP
Using GWL_USERDATA to redirect a function call? Kid's stuff! Real men use a ATL-style thunk!

DISCLAIMER: MJP does not actually advocate using this method, he is just kidding around to try to make Evil Steve look bad.
[sad]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.