CAUSE
This compiler error message occurs if a window message handler macro
has been added to the message map of a class that is not derived from
CWnd. For example, if you declare a class as
class CMyApp: public CWinApp
{
...
DECLARE_MESSAGE_MAP()
afx_msg LRESULT OnMyRegisteredMessage( WPARAM, LPARAM );
...
};
with a message map such as the following
BEGIN_MESSAGE_MAP(CMyApp,CWinApp)
ON_REGISTERED_MESSAGE( MyMSGID, OnMyRegisteredMessage )
END_MESSAGE_MAP()
the C2642 error will occur. Examine the macro ON_REGISTERED_MESSAGE()
in AFXMSG_.H; you can see why the error occurs. Here is the definition
of the macro:
// For registered Windows messages
#define ON_REGISTERED_MESSAGE(nMessageVariable, memberFxn) \
{ 0xC000, 0, (UINT)(UINT NEAR*)(&nMessageVariable), \
/*implied 'AfxSig_lwl'*/ \
(AFX_PMSG)(AFX_PMSGW) <not actual line break>
(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))memberFxn },
In MFC 4.0 (included with Visual C++ 4.0), this macro is defined as:
// for Registered Windows messages
#define ON_REGISTERED_MESSAGE(nMessageVariable, memberFxn) \
{ 0xC000, 0, 0, 0, (UINT)(UINT*)(&nMessageVariable), \
/*implied 'AfxSig_lwl'*/ \
(AFX_PMSG)(AFX_PMSGW) <not actual line break>
(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))memberFxn },
Notice that the function pointer is cast to a pointer to a function in
the CWnd scope. In the example above, CMyApp is derived only from CWinApp.
As it does not have CWnd as a base class, CMyApp will not receive window
messages. It only receives command messages that are sent through the
command routing process.