6

I am trying to build a MFC Visual Studio 6.0 project in Visual Studio 2010. The compiler gives me an error:

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

//--------------------------------- // Message map

BEGIN_MESSAGE_MAP(ProgressDialog, CDialog) ON_BN_CLICKED(IDC_CANCEL, OnCancelClicked) ON_MESSAGE(MSG_FINISHED, OnFinished) END_MESSAGE_MAP()

Any suggestions - ?

Pedro

PhilMY
  • 2,621
  • 21
  • 29
OneGuyInDc
  • 1,557
  • 2
  • 19
  • 50

2 Answers2

9

Change your ON_MESSAGE macro to ON_MESSAGE_VOID. The ON_MESSAGE macro returns a LRESULT from receiving WPARAM and LPARAM arguments. Your compiler error message states that your OnFinished() method is void arguments returning void. That's what the ON_MESSAGE_VOID macro handles.

ADDITION:

Refer to bottom of C++ Q & A -- Microsoft Systems Journal July 1999

sergiol
  • 4,122
  • 4
  • 47
  • 81
Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
1

There were breaking changes in MFC7.0, including:

The function parameter in the ON_MESSAGE macro must match the type

afx_msg LRESULT (CWnd::*)(WPARAM, LPARAM)

Your ProgressDialog::OnFinished method needs to now return an LRESULT.

Community
  • 1
  • 1
PhilMY
  • 2,621
  • 21
  • 29
  • Thanks for responding to my post Tried changing the return type to LRESULT in both the definition and declaration of Onfinished - but now I get 'static_cast' : cannot convert from 'LRESULT (__thiscall ProgressDialog::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' – OneGuyInDc May 16 '12 at 14:44
  • You also need to add the (WPARAM, LPARAM) parameters to the definition and declaration of your function. – john_e May 16 '12 at 15:49