基于对话框的串口通信:在CDebugDlg.h中,对WM_COMM_RXCHAR响应函数进行声明: // Generated message map functions
//{{AFX_MSG(CDebugDlg)
afx_msg LONG OnCommunication(WPARAM ch,LPARAM port);
//}}AFX_MSG在CDebugDlg.cpp中,对WM_COMM_RXCHAR进行消息映射:
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()并在CDebugDlg.cpp中,加入函数
LONG CDebugDlg::OnCommunication(WPARAM ch,LPARAM port)
{
return 0;
}//我新手做程序,提示有两个错误
ompiling...
debugDlg.cpp
D:\debug\debug\debugDlg.cpp(55) : error C2065: 'OnCommunication' : undeclared identifier
D:\debug\debug\debugDlg.cpp(55) : error C2440: 'type cast' : cannot convert from 'int *' to 'long (__thiscall CWnd::*)(unsigned int,long)'
        There is no context in which this conversion is possible
Error executing cl.exe.debugDlg.obj - 2 error(s), 0 warning(s)
//怎么回事?那位能帮一下

解决方案 »

  1.   

    OnCommunication 这个还需要声明?怎么声明?头文件里不算吗?
      

  2.   

    BEGIN_MESSAGE_MAP(CAboutDlg,   CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)
    //   No   message   handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP() 地方错了,得在debugDlg的消息入口处添加
      

  3.   

    得在debugDlg的消息入口处添加
    //有的书上也是那地方啊,什么标志算是消息入口处?还请ls说说,我新手
      

  4.   

    http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2483///这个也加在那地方了啊?我的怎么就不行
      

  5.   

    BEGIN_MESSAGE_MAP(CAboutDlg/*消息映射写错地方了*/,   CDialog) 
    //{{AFX_MSG_MAP(CAboutDlg) 
    ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication) 
    //   No   message   handlers 
    //}}AFX_MSG_MAP 
    END_MESSAGE_MAP() 
      

  6.   

    映射的位置不对,同时也应该在DebugDlg.cpp文件的开始对你自定义的消息进行声明
    (#define WM_COMM_RXCHAR WM_USER+***)"***"是一个值
    同时"ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)" 
    也应该放在"//}}AFX_MSG_MAP"之后 
      

  7.   

    地方错了,得在debugDlg的消息入口处添加