Popular Posts

Monday, January 2, 2012

Processing WM_DEVICECHANGE

     Each time a USB device configuration changes, the window which you registered will receive a message on message queue WM_DEVICECHANGE. Where wParam will be filled with the types of events and lParam contains a pointer to a data structure DEV_BROADCAST_HDR. The following code is an example of how to handle this message.


Procedure TUSBDeviceNotifier.WMDeviceChange(var amsg: TMessage);
begin
  case amsg.WParam of
    DBT_DEVICEARRIVAL:
        DoDeviceArrival(PDevBroadcastHdr(amsg.LParam));
    DBT_DEVICEREMOVECOMPLETE:
        DoDeviceRemoveComplete(PDevBroadcastHdr(amsg.LParam));
  end;
end;

        To obtain more specific informationyou can do a typecastDEV_BROADCAST_HDR structure to another structureaccording to type of device type that you monitor. Since we useDBT_DEVTYP_DEVICEINTERFACEthen we can typecast thelParam DEV_BROADCAST_DEVICEINTERFACE.

Technology