简体   繁体   中英

Deciphering errors in upgrading a Visual C++ 6 project to Visual Studio 2008

I wanted to see if I could bring this defunct open source project called MouseTool up to date with Windows Vista. It's a dwell-clicker to help people (like myself) who experience pain when they click the mouse. This software simulates a click when the mouse pauses at a location on the screen.

It seems like no one has touched this project in a few years so when I open it up in Visual Studio 2008, I get a ton of errors. I know very little about Visual Studio and was hoping these errors might ring a bell for someone here. Any tips that someone could provide on how I might go about starting to address some of these errors would be appreciated.

To excerpt an example, this error . . .

Error   18  error C2440: 'static_cast' : 
cannot convert from 'void (__thiscall COptionsSheet::* )(UINT,POINTS)' 
to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'   

. . . corresponds to this line:

ON_MESSAGE( WM_NCLBUTTONDOWN,   OnNCLDown )

from this block:

BEGIN_MESSAGE_MAP(COptionsSheet, CPropertySheet)
    //{{AFX_MSG_MAP(COptionsSheet)
    ON_WM_HELPINFO()
    ON_WM_MOUSEMOVE()
    ON_WM_SETCURSOR()
    //}}AFX_MSG_MAP
    ON_MESSAGE( WM_NCLBUTTONDOWN,   OnNCLDown )
    ON_MESSAGE( WM_NCLBUTTONUP,     OnNCLUp )
    ON_BN_CLICKED(ID_HELP, OnHelpButton)
END_MESSAGE_MAP()

Ring a bell for anyone?

The member signatures for certain MFC event handlers were not properly checked in vc6 - code that compiled in error in VC6 needs to be fixed to compile in the updated compiler you are using.

The handler for an ON_MESSAGE target needs to conform to this signature:

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

Your signature is this:

void (COptionsSheet::* )(UINT,POINTS)

CWnd already has this member anyway:

afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);

Use that signature instead of your own hand rolled OnNclDown.

Edit: Use ON_WM_NCLBUTTONDOWN instead of ON_MESSAGE for OnNclButtonDown.

The problem is that in the newer versions of Visual Studio, there is tighter checking on the function signatures. The old MFC macro code would let things slip, but they worked.

To fix the errors, you will need to check each of the messages in the message map and change the methods to match the signature.

WM_NCLBUTTONDOWN Notification states that it takes a WPARAM and LPARAM , which are treated as an int and a pointer to a POINTS structure. WM_NCLBUTTONDOWN通知声明它需要WPARAMLPARAM ,它们被视为int和指向POINTS结构的指针。 So if you change the signature to use WPARAM w, LPARAM l instead of UINT, POINTS and then cast the w and l parameters to the type, it should be fine.

This is more about making the signatures and functions match up really than changing how they work.

I ran into the same problem, but my class that is receiving the messages is not derived from CWnd (derived from CWinThread).

Any ideas on what what macro will let me receive a message?

Edit: Took me forever to dig through MSDN to find this, but use ON_THREAD_MESSAGE() for classes derived from CWinThread (should have figured this one...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM