Jump to content
  • Advertisement
Sign in to follow this  

Problems with function pointers and default parameters

This topic is 4411 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

I'm trying to declare a function whose last parameter is a function pointer to a window procedure (in the form of LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM )). I am also trying to provide a default parameter for that function. This default parameter is another function declared in the same header file. However, I'm getting some errors. First, here's a part of the header file:
typedef LRESULT CALLBACK LRESULT_CALLBACK;  // WARNING 1

LRESULT CALLBACK WndProcStd( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

bool CrtWindow( HINSTANCE hInstance, HWND& hWnd, int nCmdShow, const char* class_name, const char* caption,
			   LRESULT_CALLBACK (*)( HWND, UINT, WPARAM, LPARAM ) = WndProcStd );  // ERRORS 1 and 2

Here are the errors and warnings I receive: WARNING 1: warning C4229: anachronism used : modifiers on data are ignored ERROR 1: error C2440: 'default argument' : cannot convert from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to 'LRESULT_CALLBACK (__cdecl *)(HWND,UINT,WPARAM,LPARAM)' ERROR 2: error C2548: 'CrtWindow' : missing default parameter for parameter 6 What should I change in order to get this to work?

Share this post


Link to post
Share on other sites
Advertisement
If you were to use this of passing as an argument it would look like:



//WNDPROC as defined in windef.h
//typedef LRESULT (__stdcall *WNDPROC)(HWND, UINT, WPARAM, LPARAM)

//.cpp
bool CrtWindow(
HINSTANCE hInstance,
HWND& hWnd,
int nCmdShow,
const char* class_name,
const char* caption,
WNDPROC lpfnWndProc = &WndProcStd)
{
//...
WNDCLASS w;
w.lpfnWndProc = lpfnWndProc;
}









[Edited by - PiCkLeD on April 23, 2006 10:57:21 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!