internal WindowsDeviceNotifyEventArgs(DevBroadcastHdr hdr, IntPtr ptrHdr, EventType eventType)
 {
     mBaseHdr = hdr;
     mEventType = eventType;
     mDeviceType = mBaseHdr.DeviceType;
     switch (mDeviceType)
     {
         case DeviceType.Volume:
             mVolume = new VolumeNotifyInfo(ptrHdr);
             mObject = mVolume;
             break;
         case DeviceType.Port:
             mPort = new PortNotifyInfo(ptrHdr);
             mObject = mPort;
             break;
         case DeviceType.DeviceInterface:
             mDevice = new UsbDeviceNotifyInfo(ptrHdr);
             mObject = mDevice;
             break;
     }
 }
        private void OnDeviceChange(ref Message m)
        {
            
                if (!mEnabled) return;
                if (m.LParam.ToInt64() != 0) // ToInt32() only works on non-x64 platforms.
                {
                    EventHandler<DeviceNotifyEventArgs> temp = OnDeviceNotify;
                    if (!ReferenceEquals(temp, null))
                    {
                        DeviceNotifyEventArgs args;
                        DevBroadcastHdr hdr = new DevBroadcastHdr();
                        Marshal.PtrToStructure(m.LParam, hdr);
                        switch (hdr.DeviceType)
                        {
                            case DeviceType.Port:
                            case DeviceType.Volume:
                            case DeviceType.DeviceInterface:
                                args = new WindowsDeviceNotifyEventArgs(hdr, m.LParam, (EventType)m.WParam.ToInt32());
                                break;
                            default:
                                args = null;
                                break;
                        }
                        if (!ReferenceEquals(args, null)) temp(this, args);
                    }
                }

        }