[RegisterDeviceNotification] Handle connection/disconnection of a USB HID device
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.
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.