This section describes the steps you need to carry in order to receive monitored events in your code.
Obtain the Monitor
object, as described in this tutorial.
Add your listener object (for native code) to the Monitor
object or connect event handlers (for managed code):
class CMyListener : CComObjectRoot<CMyListener>, public INativeListener
{
public:
// override all pure virtual methods in the INativeListener
};
...
CComObject<CMyListener> pMyListenerObject;
CComObject<CMyListener>::CreateInstance(&pMyListenerObject);
CComPtr<INativeListener> pMyListener;
pMyListenerObject->QueryInterface(&pMyListener);
pMonitor->AddNativeListener(pMyListener);
monitor.OnOpen += new hhdspmcLib._IMonitoringEvents_OnOpenEventHandler(monitor_OnOpen);
monitor.OnPurge += new hhdspmcLib._IMonitoringEvents_OnPurgeEventHandler(monitor_OnPurge);
monitor.OnRead += new hhdspmcLib._IMonitoringEvents_OnReadEventHandler(monitor_OnRead);
...
Attach the Monitor object to the serial device:
pMonitor->Connect(CComVariant(pDevice));
monitor.Connect(device);
pMonitor->Connect(CComVariant(L"COM1"));
monitor.Connect("COM1");
pMonitor->Connect(CComVariant {VT_EMPTY});
monitor.Connect();