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.
Thanks

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

My ON_MESSAGE says:

// for Windows messages
#define ON_MESSAGE(message, memberFxn) \
	{ message, 0, 0, 0, AfxSig_lwl, \
		(AFX_PMSG)(AFX_PMSGW) \
		(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++.


Thanks

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.