Sign in to follow this  

LRESULT CALLBACK function

This topic is 3476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

}

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

This topic is 3476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this