我用VC6.0建了一个MFC 的动态库,使用了CSerialPort串口类,在此动态库中用串口进行通信,经测试能正常打开串口,关闭串口,也能发送串口数据,现在关键的是不能得到串口响应接收数据事件。响应函数全部建好了,以前在对话框中使用过一切都好,但放此动态库中就不能响应此消息,不知为什么,怎么样能让此类在动态库中也响应EV_RXFLAG | EV_RXCHAR;此事件呢。请大家帮忙看看,谢谢
afx_msg LRESULT OnCommunication(WPARAM ch,LPARAM port);
ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)
已放合适位置,。
//打开串口的程序
CWnd* pWnd = AfxGetApp()->GetMainWnd();
if (m_SerialPort.InitPort(pWnd, m_nCom,m_nBaud,m_cParity,m_nDatabits,m_nStopbits,m_dwCommEvents,512))
{
m_SerialPort.StartMonitoring();
m_bOpenPort = true;
return 1;
}
afx_msg LRESULT OnCommunication(WPARAM ch,LPARAM port);
ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)
已放合适位置,。
//打开串口的程序
CWnd* pWnd = AfxGetApp()->GetMainWnd();
if (m_SerialPort.InitPort(pWnd, m_nCom,m_nBaud,m_cParity,m_nDatabits,m_nStopbits,m_dwCommEvents,512))
{
m_SerialPort.StartMonitoring();
m_bOpenPort = true;
return 1;
}
//CWnd* pWnd = AfxGetApp()->GetMainWnd(); 或
// CWnd* pWnd = theApp.GetMainWnd();
在初始化时给定的,
if (m_SerialPort.InitPort(pWnd,...);不知道有什么不对?
if (m_SerialPort.InitPort(pWnd, m_nCom,m_nBaud,m_cParity,m_nDatabits,m_nStopbits,m_dwCommEvents,512))另外你可以自己定义一个消息在dll里向主窗口发送,看看消息是否走通了。
{
CreateEx(WS_EX_TOPMOST,AfxRegisterWndClass(CS_SAVEBITS),
"PortMana",WS_POPUP,10,10,11,11,NULL,NULL);
}
加入此关键代码 ,就有了消息响应去了就没 有了。谢谢大家 zxdlms rebort_Q的关注!