About USB - form activity


Hi everyone!

I am starting to write my first Juce app for windows first. I am dealing with USB, trying to communicate the desktop app to a microcontroller thru USB (HID so far). The thing is that, when programming in Visual Studio 2013, VS windows (forms) receive some kind of "WndProc" callback if any change in the ports happens, as USB un/connection....WM_DEVICECHANGE (devicearrival, deviceremove....)

Since Juce uses its own windows system, I can't detect this kind of behaviour...has anyone  solved how to deal wiht it?

I guess I should poll the USB ports to check if any connection happens or is still there, but i don't know if it is the best way to do it.

Any idea!?....thank you very much in advance!.




I have a thread that periodically checks the list of serial ports, and alerts my app when it changes. 


thanks for your answer,


I will try that then!


Do you alert with a callback??or some kind of global flag?






My cSerialPortMonitor class hs one job,  in a Thread, request the current list, from my modifed version of the JUCE SerialPort class (modified with the addition  of a Windows version of the getSerialPortPaths() function), compare that list to it's previous one, and set a 'changed' flag if they are different.

Then, another piece of code uses a JUCE Timer to check if this flag is set, and spins off a ThreadPool job to retrieve the new list, and create a new object (in my case it's called cNetworkEmulationUSBInterface) for each new serial port.

That code is in my library. My client code simply asks for the list when it is displaying a menu to allow the user to enable/disable a device on a given USB port.

This is still all under development, and there a bunch of cases I need to still consider, mostly to do with what happens, and where it happens, when a USB port goes away. But, that is mostly at the client code level.


Do you know  that this message only is visible when you  before call 'RegisterDeviceNotification' ?

See  https://msdn.microsoft.com/de-de/library/windows/desktop/aa363431%28v=vs.85%29.aspx .

Since Windows 8, it exist a new function for this job without the requirement to have a window handle.

But I cannot find such function call in JUCE.





Have you grepped the JUCE code for WM_DEVICECHANGE ?



The fact that you use Juce shouldn't prevent you to create your own window using CreateWindow and start listening for messages.
We create a non visible window and use RegisterDeviceNotification to listen for a certain kind of devices. On OSX you'll have to use IOKit.  Some JUCE classes that wrap this kind of stuff in a cross platform manner would be very nice.