error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CImportProjectDlg::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'
Asked Answered
F

2

6

I am converting a VC++6.0 project to Visual Studio 2008 (enroute to 2014). I am encountering the above error.

Here is my code snippet:

BEGIN_MESSAGE_MAP(CImportProjectDlg, CDialog)
//{{AFX_MSG_MAP(CImportProjectDlg)
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_WM_SIZING()
ON_WM_PAINT()
ON_WM_NCHITTEST()
ON_BN_CLICKED(IDC_MERGE_IN, OnAdd)
ON_BN_CLICKED(IDC_MERGE_OUT, OnRemove)
ON_BN_CLICKED(IDC_IMPORTPROJECT_CLEARALL, OnClearAll)
ON_BN_CLICKED(IDC_IMPORTPROJECT_APPLY, OnApply)
ON_BN_CLICKED(IDCANCEL,OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

And the error is indicated on the ON_WM_NCHITTEST() line.

Very puzzling.

Fascinating answered 24/2, 2017 at 15:31 Comment(0)
P
6

The correct signature for OnNcHitTest handler is afx_msg LRESULT OnNcHitTest(CPoint);. You have it return UINT instead of LRESULT.

Penitentiary answered 24/2, 2017 at 19:40 Comment(6)
It is unclear to me how and where to change the UINT into LRESULT.Fascinating
CImportProjectDlg has a method named OnNcHitTest. This method is currently defined to return UINT. Change it to return LRESULT.Penitentiary
I feel a little out of my depth.... do I change the declaration: UINT CImportProjectDlg::OnNcHitTest(CPoint point) to LRESULT. or do I change the return code to LRESULT?Fascinating
You change the return type from UINT to LRESULT, so the declaration becomes LRESULT CImportProjectDlg::OnNcHitTest(CPoint point)Penitentiary
The function is likely declared in an .h file, and defined in a .cpp file. You've updated it in one place but not the other. Update both.Penitentiary
Works on Windows 10/VS2017Diphyodont
S
1

If you need to let the source code compiled both on VC6 and vs2008 (unfortunately), you may use _MSC_VER to handle it.

Full list here

#if _MSC_VER >= 1500 // For vs2008+
LRESULT
#else
UINT
#endif

CImportProjectDlg::OnNcHitTest(CPoint point)
Sergu answered 16/9, 2021 at 1:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.