I'm writing some software that automatically connects a Bluetooth device using the Windows Bluetooth API. When it connects, Windows automatically starts installing the Bluetooth HID device driver, as expected:

This takes about 10-15 seconds, after which Windows displays the familar "ready for use" message:

The problem is that BluetoothSetServiceState() returns as soon as the driver install begins, not when the device is actually ready for use. This causes some problems for my code, because it invokes a separate library for device communication as soon as it's "connected". The first few calls fail because the drivers haven't finished installing, and making those connection attempts appears to interfere with the driver installation, because if I try to use the communication library before the driver installation has finished Windows wants to restart before the device can be used.
What I'm looking for is a way to hook that "ready to use" event, when driver installation has actually finished, so I don't make my communication library calls prematurely. Is there some Windows API call I can use to either register a function callback or directly polling the state of driver installation?
I'm writing this in vanilla C/C++, no .NET. Thanks for your help!
-
If it is a network binding then RNDIS sends a message when it completes installation as per RNDIS Driver Implemenation guide and definition of RNDIS
or
You can install or query the device list programatically through Devcon utility (source code is available with MSDN ) as given in Examples
-
Here is what I would do:
- Download Winspector (or use Spy++)
- Start up Winspector, and begin watching for Window Messages
- Install your driver
- Watch for WM's indicative of a completed driver installation
I wish I could be more descriptive on #4, but I'm not familiar with the specific window message you need. Have a look here for possible Window Messages to expect.
However, once you determine the correct window message to look for, then programmatically have your program wait for (and handle) this WM. CodeProject has an excellent write up on how to do this in C++. Personally, I'd prefer to do it in Delphi.
-
You might want to have a look at this sample code and RegisterDeviceNotification function. I'm not sure for 100%, but it seems to work if you specify correct guid for your device class.
Thomas : I just tried this method and it works flawlessly.
0 comments:
Post a Comment