help ... trapping DBT_DEVICEARRIVAL in Windows2000

Discussion in 'Windows Vista Drivers' started by Neo, Oct 11, 2003.

  1. Neo

    Neo Guest

    hi,

    I've got an application which checks for the
    WM_DEVICECHANGE message w/ the DBT_DEVICEARRIVAL message.
    I have done this by using the RegisterDeviceNotification() call.

    Basically looking for an insertion of a USB devices. For testing
    purposes I used a USB mouse. I expected to trap DBT_DEVICEARRIVAL
    message. Instead I am always getting DBT_DEVNODES_CHANGED.



    This is the code I have used.

    /* This section is done in the InitDialog() section */

    if (DoRegisterDeviceInterface (GUID_CLASS_USB_DEVICE
    &hNotification) == TRUE)
    AfxMessageBox("DoRegisterDeviceInterface GUID_CLASS_USB_DEVICE
    SUCCESS");
    else
    AfxMessageBox ("DoRegisterDeviceInterface GUID_CLASS_USB_DEVICE
    FAILED");


    if (DoRegisterDeviceInterface (GUID_CLASS_USB_DEVICE,
    &hNotification) == TRUE)
    AfxMessageBox ("DoRegisterDeviceInterface GUID_CLASS_USBHUB SUCCESS");
    else
    AfxMessageBox ("DoRegisterDeviceInterface GUID_CLASS_USBHUB FAILED");





    BOOL DoRegisterDeviceInterface(GUID InterfaceClassGuid, HDEVNOTIFY
    *hDevNotify)
    {
    DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
    DWORD Err;

    ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
    NotificationFilter.dbcc_size =
    sizeof(DEV_BROADCAST_DEVICEINTERFACE);
    NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;

    NotificationFilter.dbcc_classguid = InterfaceClassGuid;

    *hDevNotify = RegisterDeviceNotification( GetDesktopWindow(),
    &NotificationFilter,
    DEVICE_NOTIFY_WINDOW_HANDLE
    );

    if(!*hDevNotify)
    {
    Err = GetLastError();
    AfxMessageBox( "RegisterDeviceNotification failed: %lx.\n",
    Err);
    return FALSE;
    }

    return TRUE;
    }



    LRESULT CUsb786Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM
    lParam)
    {
    int s32Temp;
    char as8Temp[10];

    switch (message)
    {
    HANDLE_MSG (GetDesktopWindow()->GetSafeHwnd(), WM_DEVICECHANGE,
    Usb_OnDeviceChange);
    }


    BOOL Usb_OnDeviceChange
    (
    HWND hwnd,
    UINT uEvent,
    DWORD dwEventData
    )
    {
    int s32Temp;
    char as8Temp[10];
    BOOL bResult;
    SP_DEVINFO_DATA strDevInfoData;
    SP_DEVICE_INTERFACE_DATA strDevInterfaceData;

    AfxMessageBox ("Device Changed");
    switch (uEvent)
    {
    case DBT_DEVNODES_CHANGED:
    AfxMessageBox ("DBT_DEVNODES_CHANGED");
    break;
    case DBT_CONFIGCHANGECANCELED:
    AfxMessageBox (" DBT_CONFIGCHANGECANCELED ");
    break;
    case DBT_CONFIGCHANGED:
    AfxMessageBox ("DBT_CONFIGCHANGED ");
    break;
    case DBT_CUSTOMEVENT:
    AfxMessageBox ("DBT_CUSTOMEVENT ");
    break;
    case DBT_DEVICEARRIVAL:
    AfxMessageBox (" DBT_DEVICEARRIVAL ");
    break;
    case DBT_DEVICEQUERYREMOVE:
    AfxMessageBox ("DBT_DEVICEQUERYREMOVE ");
    break;
    case DBT_DEVICEQUERYREMOVEFAILED:
    AfxMessageBox ("DBT_DEVICEQUERYREMOVEFAILED ");
    break;
    case DBT_DEVICEREMOVECOMPLETE:
    AfxMessageBox ("DBT_DEVICEREMOVECOMPLETE ");
    break;
    case DBT_DEVICEREMOVEPENDING:
    AfxMessageBox ("DBT_DEVICEREMOVEPENDING ");
    break;
    case DBT_DEVICETYPESPECIFIC:
    AfxMessageBox ("DBT_DEVICETYPESPECIFIC ");
    break;
    case DBT_QUERYCHANGECONFIG:
    AfxMessageBox (" DBT_QUERYCHANGECONFIG ");
    break;
    case DBT_USERDEFINED:
    AfxMessageBox ("DBT_USERDEFINED ");
    break;
    }

    return TRUE;
    }


    please Help me out.
    thanks.
     
    Neo, Oct 11, 2003
    #1
    1. Advertisements

  2. GUID_CLASS_USB_DEVICE is not interface class. It is PNP device class. You
    won't get notifications for such GUID.

     
    Alexander Grigoriev, Oct 11, 2003
    #2
    1. Advertisements

  3. Neo

    Neo Guest

    hi,

    " GUID_CLASS_USB_DEVICE is not interface class. It is PNP device
    class. You
    won't get notifications for such GUID."


    Could you tell me where to look for interface class GUIDs for Usb
    mouse and Bulk transfer devices.

    Surej.
     
    Neo, Oct 15, 2003
    #3
    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.