I'm writing a C++ application that communicates with a Bluetooth device, and
that device restricts me to using the serial port profile. Using the
Platform SDK Bluetooth APIs (defined in BluetoothAPIs.h) on Windows XP
Service Pack 2, my application is able to programmatically discover, pair
with, and connect to a Bluetooth device without any user intervention at all.
My problem lies in trying to determine which virtual serial port a given
Bluetooth device gets mapped to.
To connect to the serial port service on my Bluetooth device, my code makes
the following call:
GUID service = SerialPortServiceClass_UUID; // from bthdef.h
lastError = BluetoothSetServiceState( radioHandle, &bluetoothDeviceInfo,
&service, BLUETOOTH_SERVICE_ENABLE );
When that function is called, Windows automatically creates a virtual serial
port for my application to use for outgoing communication with my Bluetooth
device. Great! That saves me the hassle of calling RegisterDevice. There's
only one problem -- which virtual serial port just got created? (It's not
always COM7 or COM8.)
But the problem gets more complicated. Imagine that the user quits my
application, comes back a couple of hours later, and starts my application up
again. At this point, I can programmatically go through and find out that
Bluetooth device X has been connected before and has been authenticated
(paired). But which virtual serial port should I open to communicate with
device X? Obviously this information is stored somewhere, because it is
presented when I open Control Panel->Bluetooth Devices->COM Ports. But how
can my application access that information?
In short, the task is to start with a BLUETOOTH_DEVICE_INFO structure and
end up with a virtual serial port number. What functions do I need to call
to access that information?