public void RegisterDeviceNotification(Guid guid, WindowInteropHelper windowInteropHelper)
        {
            DEV_BROADCAST_DEVICEINTERFACE devIF = new DEV_BROADCAST_DEVICEINTERFACE();
            IntPtr devIFBuffer;

            //Set to HID GUID
            devIF.dbcc_size       = Marshal.SizeOf(devIF);
            devIF.dbcc_devicetype = USBPnpDetection.DBT_DEVTYP_DEVICEINTERFACE;
            devIF.dbcc_reserved   = 0;
            devIF.dbcc_classguid  = guid;

            //AloCATE A buffer for DLL call
            devIFBuffer = Marshal.AllocHGlobal(devIF.dbcc_size);

            //Copy devIF to buffer
            Marshal.StructureToPtr(devIF, devIFBuffer, true);

            //Register for HID device notification
            m_hNotifyDevNode = USBPnpDetection.RegisterDeviceNotification(windowInteropHelper.Handle, devIFBuffer, USBPnpDetection.DEVICE_NOTIFY_WINDOW_HANDLE);

            //Copy buffer to devIF
            devIF = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(devIFBuffer, typeof(DEV_BROADCAST_DEVICEINTERFACE));

            //Free buffer
            Marshal.FreeHGlobal(devIFBuffer);
        }
        public DeviceInfo_t GetHIDDeviceInfo(DEV_BROADCAST_DEVICEINTERFACE dvi)
        {
            DeviceInfo_t deviceInfo = new DeviceInfo_t();

            string dbcc_name = new string(dvi.dbcc_name);

            dbcc_name = RemoveNullTerminatedFromString(dbcc_name);

            string[] parts = dbcc_name.Split('#');
            if (parts.Length >= 3)
            {
                deviceInfo.DevType          = parts[0].Substring(parts[0].IndexOf(@"?") + 2);
                deviceInfo.DeviceInstanceId = parts[1];
                deviceInfo.DeviceUniqueID   = parts[2];
            }
            return(deviceInfo);
        }