Jump to content
  • Advertisement
Sign in to follow this  
wforl

LRESULT CALLBACK function

This topic is 3754 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
Advertisement
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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!