I'm writing a DLL library that interfaces to a USB device using winusb in VB.NET.
Since it's a DLL, I have no window, and it's possible that users of my library will also not have a window (command line apps, for instance).
The examples I've seen that detect device attach and detach all use RegisterDeviceNotification
which requires a window handle to receive the attach/detach messages at.
How do I receive these messages directly into a function without a window to get a handle from?
While this isn't for .NET, it provides a template in C++ for the process of creating the structures necessary to handle the window callbacks, and provides a way to register a custom window handle without having a real window:
http://msdn.microsoft.com/en-us/library/aa363432%28VS.85%29.aspx
I recently found a solution that seems more elegant than RegisterDeviceNotification for an application without a GUI.
Initialize this code by calling
Also make sure to add a reference to System.Management