USB Monitoring Control - TODO
Download USB Monitoring Control Hide this button

How to Receive Monitored Events

This section describes the steps you need to carry in order to receive monitored events in your code.

  1. Obtain the Monitor object, as described in this tutorial.

  2. Add your listener object (for native code) to the Monitor object or connect event handlers (for managed code):

    class CMyListener : public CComObjectRoot<CMyListener>, public INativeListener
        // override all pure virtual methods in the INativeListener
        STDMETHOD(OnGetDescriptorFromDevice)(FILETIME *fTime,void* Data,ULONG Size,BYTE Index,BYTE DescriptorType,USHORT LanguageId);
        // ...
    CComObject<CMyListener> pMyListenerObject;
    CComPtr<INativeListener> pMyListener;
    monitor.OnConnection += new hhdusbmcLib._IMonitoringEvents_OnConnectionEventHandler(monitor_OnConnection);
    monitor.OnPacketUp += new hhdusbmcLib._IMonitoringEvents_OnPacketUpEventHandler(monitor_OnPacketUp);
    monitor.OnPacketDown += new hhdusbmcLib._IMonitoringEvents_OnPacketDownEventHandler(monitor_OnPacketDown);
  3. Attach the Monitor object to the USB device:

    • Attach to the given USB device:

      pMonitor->Connect(CComVariant(pDevice), /*headers-only*/ CComVariant(VARIANT_FALSE));
      hhdusbmcLib.Device device  = monitor.Devices[nIndex];
      monitor.Connect(device, /*headers-only*/ false);
    • Attach to the next USB device the user plugs into the computer:

      CComPtr<IDeviceCollection> pDeviceCollection;
      HRESULT hr = m_pUM->get_Devices(&pDeviceCollection);
          return hr;
      CComPtr<IDevice> pDevice;
      // first item is always NextConnected
      pMonitor->Connect(pDevice, /*headers-only*/ CComVariant(VARIANT_FALSE));
      // first device is always NextConnected device
      hhdusbmcLib.Device device  = monitor.Devices[0];
      monitor.Connect(device, /*headers-only*/ false);