コード例 #1
0
        private void RegisterUsbDeviceNotification()
        {
            var dbi = new NativeMethods.DevBroadcastDeviceinterface
            {
                DeviceType = DbtDevtypDeviceinterface,
                Reserved   = 0,
                ClassGuid  = _guidDevinterfaceUsbDevice,
                Name       = 0
            };

            dbi.Size = Marshal.SizeOf(dbi);
            var buffer = Marshal.AllocHGlobal(dbi.Size);

            Marshal.StructureToPtr(dbi, buffer, true);

            _notificationHandle = NativeMethods.RegisterDeviceNotification(_windowHandle, buffer, 0);
        }
コード例 #2
0
		private void RegisterUsbDeviceNotification()
		{
			var dbi = new NativeMethods.DevBroadcastDeviceinterface
			{
				DeviceType = DbtDevtypDeviceinterface,
				Reserved = 0,
				ClassGuid = _guidDevinterfaceUsbDevice,
				Name = 0
			};

			dbi.Size = Marshal.SizeOf(dbi);
			var buffer = Marshal.AllocHGlobal(dbi.Size);
			Marshal.StructureToPtr(dbi, buffer, true);

			_notificationHandle = NativeMethods.RegisterDeviceNotification(_windowHandle, buffer, 0);
		}