I converted old C++ project to VS.Net 2010 with 4.0 Framework.
error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatView:: * )(LPARAM,WPARAM)' to 'LRESULT (__thiscall CWnd:: * )(WPARAM,LPARAM)'

// .cpp File
ON_MESSAGE(WM_ChatAddSize, OnChatAddSize)

void CChatView::OnChatAddSize(LPARAM lParam, WPARAM wParam)

// .h file
afx_msg void OnChatAddSize(LPARAM lParam, WPARAM wParam);

Help would be really appreciated.

Edited by chintan_1671: n/a

5 Years
Discussion Span
Last Post by thekashyap

Your function needs to return a LRESULT, not void. And your parameters are inverted

Edited by mike_2000_17: n/a



// for Windows messages
#define ON_MESSAGE(message, memberFxn) \
	{ message, 0, 0, 0, AfxSig_lwl, \
		(static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) > \
		(memberFxn)) },

I changed the code to:

// .cpp
ON_MESSAGE(WM_ChatAddSize, OnChatAddSize)

LRESULT CChatView::OnChatAddSize(WPARAM wParam, LPARAM lParam)

    return (LRESULT)0;

// .h File
afx_msg LRESULT OnChatAddSize(WPARAM wParam, LPARAM lParam);

And i have following constructor in my .cpp file.

CChatView::CChatView(CWnd* pParent /*=NULL*/)
:	CDialog(CChatView::IDD, pParent)

This is not giving any compile error.
But i am not getting proper output.
Does changing this changes the pointer values.
I debugged this a bit and feel that pointers are creating some problem.

I am new to Win C++.


Edited by chintan_1671: n/a


error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatView:: * )(LPARAM,WPARAM)' to 'LRESULT (__thiscall CWnd:: * )(WPARAM,LPARAM)'

It's been 10 years since I did some MFC so don't really remember.

But from teh error msg itself you can deduce this:
Your declaration translates to: void (__thiscall CChatView:: * )(LPARAM,WPARAM) expected signature is this: LRESULT (__thiscall CWnd:: * )(WPARAM,LPARAM) So:
1. Return type is LRESULT as mike pointed out.
2. Parameters are to be swapped as you did. WPARAM is expected.
3. CChatView => CWnd

You've corrected first two but not the last. Don't ask me how, coz I donno. :)

I suggest you look at the pre-processor version of your .cpp and things might a bit more clear. With MFC and it's macros things are not always obvious.
Usually it's the -E option to compiler to generate the pre-processed output.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.