串口通讯的问题,使用CSerialPort类
在SerialPortTestDlg.h中,对WM_COMM_RXCHAR响应函数进行声明:
// Generated message map functions
//{{AFX_MSG(CDebugDlg)
afx_msg LONG OnComm(WPARAM ch,LPARAM port);
//}}AFX_MSG在CSerialPortTestDlg.cpp中,对WM_COMM_RXCHAR进行消息映射:
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()并在CSerialPortTestDlg.cpp中,加入函数
LONG CSerialPortTestDlg::OnComm(WPARAM ch,LPARAM port)
{
m_strEditReceiveMsg+=ch;
UpdateData(FALSE);
return 0;
} 为什么会出现error C2065: 'OnComm' : undeclared identifier??
在SerialPortTestDlg.h中,对WM_COMM_RXCHAR响应函数进行声明:
// Generated message map functions
//{{AFX_MSG(CDebugDlg)
afx_msg LONG OnComm(WPARAM ch,LPARAM port);
//}}AFX_MSG在CSerialPortTestDlg.cpp中,对WM_COMM_RXCHAR进行消息映射:
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()并在CSerialPortTestDlg.cpp中,加入函数
LONG CSerialPortTestDlg::OnComm(WPARAM ch,LPARAM port)
{
m_strEditReceiveMsg+=ch;
UpdateData(FALSE);
return 0;
} 为什么会出现error C2065: 'OnComm' : undeclared identifier??
ON_MESSAGE(WM_COMM_RXCHAR,SerialPortTestDlg::OnComm)怎么一个CDebugDlg,一个CAboutDlg??
//{{AFX_MSG_MAP(CAboutDlg)
ON_MESSAGE(WM_COMM_RXCHAR,OnComm)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()很明显,你加错地方了,你加到About对话框类中去了