I am working on a MDI application that has a 'widget' object that does not inherit from any of the objects in the application. The 'widget' uses the MS Communications Control (mscomm32.ocx - converted to H/CPP files when component is inserted).
I do not have any problems sending data from the MDI app to a remote computer; I cannot get the OnCommEvent to work.
Because I am new to the Com Control, I have been working from MS's VCTERM example - which uses a dialog box.
The widget object doesn't inherit from any application object, so I have tried inheriting from CObject, CCmdTarget, CWnd, and CDialog, as well as my app's Application and Frame classes along with the main document's Doc, Frame, and View classes. (Esentially the shotgun method, hoping something would work).
CObject doesn't compile: error C2039 'eventsinkmap' is not a member of CObject
CCmdTarget, CWnd, and CDialog all compile without errors or warnings, but do not respond to events on the serial port.
[I'm sending data via HyperTerminal on a second computer and have a Protocol Analyzer in the middle - I know the data is moving]
ID_COMMCTRL has been defined in 'resource.h'
My code is as follows:
widget.h
widget.cpp
// add eventsink map to hook OnComm event
/* OnComm */
// Create the MSCOMM32 OLE Control.
Thanks in advance
I do not have any problems sending data from the MDI app to a remote computer; I cannot get the OnCommEvent to work.
Because I am new to the Com Control, I have been working from MS's VCTERM example - which uses a dialog box.
The widget object doesn't inherit from any application object, so I have tried inheriting from CObject, CCmdTarget, CWnd, and CDialog, as well as my app's Application and Frame classes along with the main document's Doc, Frame, and View classes. (Esentially the shotgun method, hoping something would work).
CObject doesn't compile: error C2039 'eventsinkmap' is not a member of CObject
CCmdTarget, CWnd, and CDialog all compile without errors or warnings, but do not respond to events on the serial port.
[I'm sending data via HyperTerminal on a second computer and have a Protocol Analyzer in the middle - I know the data is moving]
ID_COMMCTRL has been defined in 'resource.h'
My code is as follows:
widget.h
Code:
class Widget: public [CObject/CWnd/...]
{
public:
CLaserObj();
OnCommEvent();
DECLARE_EVENTSINK_MAP()
....
widget.cpp
// add eventsink map to hook OnComm event
Code:
BEGIN_EVENTSINK_MAP(CLaserObj, CDialog)
ON_EVENT(CLaserObj, ID_COMMCTRL, 1
Code:
, OnCommEvent, VTS_NONE)
END_EVENTSINK_MAP()
Widget::Widget()
{
Code:
if (!m_comm_ctrl.Create(NULL,0,CRect (0,0,0,0),myApp.m_pMainWnd,ID_COMMCTRL))
{
TRACE0("Failed to create OLE Communications Control\n");
}
...
}
void Widget::InitializeCommPort()
{
m_comm_ctrl.SetCommPort(1); //COM1
m_comm_ctrl.SetHandshaking(1);//XonXoff
m_comm_ctrl.SetInputMode(0); //treat as text (1 - binary)
m_comm_ctrl.SetSettings("9600,N,8,1");//9600 baud, NO parity, 8 data bits, 1 stop bit
}
void Widget::OnCommEvent()
{
AfxMessageBox("OnCommEvent()");
}
Thanks in advance