Migrating from VC6 to VS2005 | Beyond C++

by stilling2006 on 2010-06-21 18:22:27

Recently, the development platform has been upgraded from VC6.0 to VS2005, and it is necessary to migrate the existing projects. The problems encountered during this process are summarized as follows:

1. **Message Mapping**

VS2005 performs stricter checks on messages. Message mappings that ran perfectly fine under VC6.0 may fail to compile under VS2005.

a. **ON_MESSAGE(message, OnMyMessage)**

The return type of `OnMyMessage` must be `LRESULT`, and its format should be: `afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);`. If this requirement is not met, the following error will occur:

```

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

```

The error indicates that there is no function with the specified name within the scope of the target type.

b. **ON_COMMAND_EX(id, OnMyMessage2)**