DOC: C2642 in Message Map Caused by Incorrect Prototypes

ID: q85521


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft C/C++ for MS-DOS, version 7.0
    • Microsoft Visual C++ for Windows, 16-bit edition, version 1.0
    • Microsoft Visual C++, 32-bit Editions, version 1.0


SYMPTOMS

An attempt to use the message-map mechanism provided by the Microsoft Foundation Classes fails and the compiler generates the following message:

error C2642: cast to pointer to member must be from related pointer to member


CAUSE

The function declarations in the message map do not match the function prototypes declared in the AFXWIN.H file.


RESOLUTION

Compare the message-handler function prototypes in your application to those in the AFXWIN.H file. Verify that the parameter types and return types match.


MORE INFORMATION

Functions that process Windows messages can be defined as member functions of a derived window class. To use the message-routing mechanism the Microsoft Foundation Classes provided by the DECLARE_MESSAGE_MAP, BEGIN_MESSAGE_MAP, and END_MESSAGE_MAP functions, the function declarations in the derived class must exactly match the function parameters specified in AFXWIN.H.

The "Microsoft C/C++ Class Libraries Reference" manual and online help files provided with Microsoft C/C++ version 7.0 and with Microsoft Visual C++ version 1.0 incorrectly document the prototypes for the following message-handler functions, as follows:


   afx_msg void OnHScroll(UINT, UINT, CWnd *);
   afx_msg void OnVScroll(UINT, UINT, CWnd *);
   afx_msg int OnCharToItem(UINT, CWnd *, UINT);
   afx_msg int OnVKeyToItem(UINT, CWnd *, UINT); 
The AFXWIN.H file and the ERRATA2.TXT file provided with C/C++ version 7.0 list the corrected function prototypes as follows:

   afx_msg void OnHScroll(UINT, UINT, CScrollBar *);
   afx_msg void OnVScroll(UINT, UINT, CScrollBar *);
   afx_msg int OnCharToItem(UINT, CListBox *, UINT);
   afx_msg int OnVKeyToItem(UINT, CListBox *, UINT); 
The "Class Libraries Reference" manual for C/C++ version 7.0 and the online help for C/C++ version 7.0 and Visual C++ version 1.0 incorrectly document the prototype for the following message-handler function:

   afx_msg void OnNcCalcSize(LPRECT); 
The AFXWIN.H and ERRATA2.TXT files list the corrected function prototype as follows:

   afx_msg void OnNcCalcSize(NCCALCSIZE_PARAMS FAR *); 
The online help for Visual C++ version 1.5 and Visual C++ 32-bit Edition has the correct information.

The following message-handler functions are not listed in the "Class Libraries Reference" manual, but they are listed in the online help:

   afx_msg void OnWindowPosChanging(WINDOWPOS FAR *);
   afx_msg void OnWindowPosChanged(WINDOWPOS FAR *);
   afx_msg void OnDropFiles(HANDLE);
   afx_msg void OnPaletteIsChanging(CWnd *); 
The message-handler function prototypes in the AFXWIN.H file are correct.

This message can also be caused from using the ON_MESSAGE macro (in MFC 2.0) with command handler classes such as CDocument or CWinApp. This is because these classes aren't derived from CWnd, and the ON_MESSAGE macro doesn't make sense in non-CWnd derived classes.

Additional query words: 7.00 1.00 2.00 2.10 afx

Keywords :
Version :
Platform :
Issue type :


Last Reviewed: December 21, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.