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