[RegisterDeviceNotification] Handle connection/disconnection of a USB HID device
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    Hello,

    I'm currently trying to handle USB HID device notifications using HID library from Windows Development Kit.
    I'm using a HID device (SpacePoint Fusion, for those who are interested) and I can detect it, open it and read data from it without any issue.
    My problem is concerning RegisterDeviceNotification function, which enables to get noticed when an event has occured concerning the device (eg. connection/disconnection).

    Everything works fine for a MFC application, but not for a Win32 console application.
    The first parameter of RegisterDeviceNotification method is the handle of the window that will process the events. So I'm using the handle of the window console, the return of the function (HDEVNOTIFY type) seems to notice me that everything went fine since GetLastError() returns 0.
    The problem is that the message processing function (WindowProc) is never called, so I don't have any chance to see a WM_DEVICECHANGE event happen.

    Does anyone has an idea for this issue ?

    Regards,
    Aymeric.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,930

    Re: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    You have to have 'normal' window in a separate thread to catch notifications. The window is not obliged to be visible anyhow, and it can be a message-only window alright.

    The main problem with console window is: the window procedure is not controlled/monitored by your application like this is done in case of MFC window.
    Last edited by Igor Vartanov; April 28th, 2011 at 10:34 AM.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2011
    Posts
    3

    Re: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    Thanks a lot for your answer Igor.
    I will use a message-only window for my purpose since I didn't find another solution.

    By the way, do you know if it's possible to use the same way for a DLL ?
    Because then I'm planning to develop a DLL for my device.

    Regards,
    Aymeric.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,787

    Re: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    I wouldn't use HWND_MESSAGE either - http://www.codeguru.com/forum/showpo...00&postcount=2

    gg

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,930

    Re: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    I cannot see any problem with DLL. In fact, it makes no difference, as both EXE and DLL are executable modules.

    And yes, that info from Codeplug is something new to me, and this way I would follow his recommendation of creating plain non-visible window.
    Best regards,
    Igor

  6. #6
    Join Date
    Apr 2011
    Posts
    3

    Re: [RegisterDeviceNotification] Handle connection/disconnection of a USB HID device

    Thanks to both of you.
    Actually, I followed Codeplug recommendation by creating a plain non-visible window.
    This works fine, I've just added some code to make sure the device which has been attached/removed is the one I'm interested in.
    Now, everything's working well and I'll implement it in my DLL.

    Thanks again.

    Regards,
    Aymeric.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center