Friso1990 Friso1990 - 11 months ago 56
C++ Question

C2440 for overloaded function MsgProc

This is a continuation from this question.

I have the following assignment:

sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0, 0,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL
wc = wndClass;

Which gives me the following error:

1>e:\rat_engine\rat_engine\rat_engine\rat_rendererdx9.cpp(19): error
C2440: 'initializing' : cannot convert from 'overloaded-function' to

1>None of the functions with this name in scope
match the target type

With MsgProc underlined as the cause, it should reference the following function:

LRESULT WINAPI RAT_RendererDX9::MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
switch( msg )
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
ValidateRect( hWnd, NULL );
return 0;

return DefWindowProc( hWnd, msg, wParam, lParam );

In the tutorial it works like this and I have copied it almost exactly. So where does the error come from and how can I fix it?


The declaration of MsgProc is:

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );

Answer Source

From your declaration of MsgProc it seems that it's a regular member function, which means it takes a "hidden" this pointer. That makes it incompatible with WNDPROC and that's why the compiler complains.

Trying marking it as static. Of course, this means that you cannot access non-static members of the class easily - you will need to stash a copy of the this pointer of the instance you want somewhere to do that.

You may also need CALLBACK instead of WINAPI but I don't have easy access to a compiler to verify this at this time.