Sign in to follow this  
v0dKA

Problems with function pointers and default parameters

Recommended Posts

v0dKA    568
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
PiCkLeD    188
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

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