[API]
DEV_BROADCAST_HANDLE
RegisterDeviceNotificationA
Public UnregisterDeviceNotification
CreateFileA
CloseHandle

[INCLUDE]
RemovableDevices_Unregister

[DEFINE]
Private RemovableDevices_Handle(0& To 25&) As Long

[CODE]
Public Function RemovableDevices_Register(ByVal hWnd As Long, ByVal DriveLetterID As Long) As Boolean
  Dim NotificationFilter As DEV_BROADCAST_HANDLE

#If Unicode Then
  If IsUnicode Then
#End If
    NotificationFilter.dbch_handle = CreateFileA(Chr(DriveLetterID + 65&) + ":\\", &H80000000, 3&, 0&, 3&, &H2000080, 0&)
    If Not NotificationFilter.dbch_handle = -1& Then
      NotificationFilter.dbcc_size = Len(NotificationFilter)
      NotificationFilter.dbcc_devicetype = 6&
      On Error GoTo Er1
      RemovableDevices_Handle(DriveLetterID) = RegisterDeviceNotificationA(hWnd, NotificationFilter, 0&)
Rs1:
      On Error GoTo 0
      Call CloseHandle(NotificationFilter.dbch_handle)
      RemovableDevices_Register = (Not (RemovableDevices_Handle(DriveLetterID) = 0&))
      End If
#If Unicode Then
    End If
#End If
  Exit Function

Er1:
  Resume Rs1
  End Function
