Click to See Complete Forum and Search --> : From VC++ 6 to VC++ 7


miteshpandey
September 6th, 2004, 10:24 AM
I have downloaded code from the code guru and it compiles well in VC++ 6 but some problems in VC++ 7.

The following error is displayed.

c:\My Documents\Mitesh\Portal\ChatRoom\ChatRoomDlg.cpp(138): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CChatRoomDlg::* )(WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

What should I do rectify the error.

Please Help.

JohnCz
September 6th, 2004, 10:43 AM
You did not post any code. Post the line than is causing this error.

miteshpandey
September 6th, 2004, 10:52 AM
Sorry,

The error appears on the following line.

BEGIN_MESSAGE_MAP(...)

..................
..................
ON_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()

MyMessageHandler(...) function is declared as following:

LRESULT MyMessageHandler(WPARAM wp, LPARAM lp);

Please Help

miteshpandey
September 6th, 2004, 10:54 AM
Sorry,

The error appears on the following line (ON_MESSAGE(...)).

BEGIN_MESSAGE_MAP(...)

..................
..................
ON_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()

MyMessageHandler(...) function is declared as following:

LRESULT MyMessageHandler(WPARAM wp, LPARAM lp);

Please Help

JohnCz
September 6th, 2004, 11:10 AM
If you posted your code verbatim, I do not see a reason for this error without error C2511.
Check declaration and definition of MyMessageHandler. You are missing LPARAM in formal parameter list. that code should compile with the same error in VS6.

miteshpandey
September 6th, 2004, 04:16 PM
I am having this problem in two applications downloaded from Codeguru. The application are developed in VC++ 6 and I am converting them to VC++ 7. I assume that the program is bug free in VC++6.

The first program is a chat program and the error appear in the colored line.


BEGIN_MESSAGE_MAP(CChatRoomDlg, CExpandingDialog)
//{{AFX_MSG_MAP(CChatRoomDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTNSEND, OnBtnsend)
ON_WM_CLOSE()
ON_COMMAND(ID_CONNECT, OnConnect)
ON_COMMAND(ID_SIGN_IN, OnSignIn)
ON_COMMAND(IDC_CHAR_BOLD, OnCharBold)
ON_COMMAND(IDC_CHAR_COLOR, OnCharColor)
ON_COMMAND(IDC_CHAR_ITALIC, OnCharItalic)
ON_COMMAND(IDC_CHAR_STRIKEOUT, OnCharStrikeout)
ON_COMMAND(IDC_CHAR_UNDERLINE, OnCharUnderline)
ON_COMMAND(ID_MYLOGO, OnMylogo)
ON_COMMAND(ID_AWAY, OnAway)
ON_BN_CLICKED(IDC_DETAILS, OnDetails)
ON_UPDATE_COMMAND_UI(ID_CONNECT, OnUpdateConnect)
ON_UPDATE_COMMAND_UI(IDC_CHAR_ITALIC, OnUpdateCharItalic)
ON_UPDATE_COMMAND_UI(IDC_CHAR_STRIKEOUT, OnUpdateCharStrikeout)
ON_UPDATE_COMMAND_UI(IDC_CHAR_UNDERLINE, OnUpdateCharUnderline)
ON_UPDATE_COMMAND_UI(IDC_CHAR_BOLD, OnUpdateCharBold)
ON_UPDATE_COMMAND_UI(ID_AWAY, OnUpdateAway)
ON_UPDATE_COMMAND_UI(ID_SIGN_IN, OnUpdateSignIn)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_UPDATE_COMMAND_UI(IDC_CHAR_COLOR, OnUpdateCharColor)
ON_UPDATE_COMMAND_UI(ID_MYLOGO, OnUpdateMylogo)
ON_COMMAND(ID_SIGN_OUT, OnSignOut)
ON_UPDATE_COMMAND_UI(ID_SIGN_OUT, OnUpdateSignOut)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE,OnKickIdle)

ON_MESSAGE(WM_UPDATECHARFORMAT,UpdateCharFormat4Input)


END_MESSAGE_MAP()


The function UpdateCharFormat4Input is declared as follows:

afx_msg LRESULT CChatRoomDlg::UpdateCharFormat4Input(WPARAM param);

The error displayed is

c:\My Documents\Mitesh\Portal\ChatRoom\ChatRoomDlg.cpp(138): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CChatRoomDlg::* )(WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'


The other program that gives error has following functions:

afx_msg void OnStartRecording(WPARAM wp,LPARAM lp);
afx_msg void OnStopRecording(WPARAM wp,LPARAM lp);
afx_msg void OnEndThread(WPARAM wp,LPARAM lp);

The error is shown in the corresponding ON_MESSAGE message map item.

miteshpandey
September 6th, 2004, 05:02 PM
Thanx John for everything.

The problem is now solved.

In the first program I was missing out the LPARAM parameter in the declaration.

and in the second program I should have declared the function starting with LRESULT instead of void.

One thing this proves is that VC++ 7 has more stricter type checking than VC++6.

Thanx again

JohnCz
September 7th, 2004, 07:27 AM
Yes, it is.
You are welcome.