USB: WM_DEVICECHANGE, DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE

Discussion in 'Windows Vista Drivers' started by Robin, Aug 9, 2004.

  1. Robin

    Robin Guest

    Hi

    I have a USB device using the usbser.sys to map the device to the COM
    port. I'd like to have a proper handling when pluggin/re-plugging the
    device. This means, I have to close the handle when the device gets
    unplugged.

    I have a user-app that might be connected to the device (via COM port)
    when it gets removed. I read in the Platform SDK and found out that I
    need to listen to WM_DEVICECHANGE and maybe would have to use
    RegisterDeviceNotification as well.

    When I listen to WM_DEVICECHANGE in my app, I only get
    DBT_DEVNODES_CHANGED. But in the SDK docu, it says:"The
    DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events are automatically
    broadcast to all top-level windows for port devices." - and a port
    device is exactly what I have, no? But I don't get the messages as
    mentioned.

    So what is the proper way to solve this problem? Do I have to call
    RegisterDeviceNotification? If yes, where? With what kind of
    DEV_BROADCAST_HDR (what's best experience here)? What about multiple
    devices attached?

    Many thanks

    Robin
     
    Robin, Aug 9, 2004
    #1
    1. Advertisements

  2. Eliyas Yakub [MSFT], Aug 9, 2004
    #2
    1. Advertisements

  3. Follow the DDK\src\general\toaster\exe\notify sample in the DDK.
     
    Eliyas Yakub [MSFT], Aug 9, 2004
    #3
  4. Robin

    Robin Guest

    Many thanks.

    I know now, that I have to register at the beginning of the app and
    unregister when closing.

    But I couldn't figure out what I need to register for. The toaster
    example handles a bus (as far as I could understand). And it begins with
    registering for DBT_DEVTYP_DEVICEINTERFACE.

    In the SDK documentation it says:"The DBT_DEVICEARRIVAL and
    DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all
    top-level windows for port devices.", so I think this should work also
    for COM port. But I don't get the events.

    When I look at RegisterDeviceNotification, I come to the conclusion that
    I should register for the DBT_DEVTYP_PORT type in DEV_BROADCAST_HDR. But
    there I need to hand over a device name ("COM%d"), but I don't know the
    number of the port, because I don't know before it gets attached.

    I think I should somehow get the DBT_DEVICEARRIVAL event, figure out if
    it's one of our devices, and then register for removal events for this
    port or handle to close it and unregister again. But I don't know how to
    get this DBT_DEVICEARRIVAL.

    Many thanks

    Robin
     
    Robin, Aug 10, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.