问题
I maintain an application that, amongst other things, provides a list to the user of available serial port devices on the host computer. This application makes use of the GetDefaultCommConfig() function in order to verify that devices in its list of serial port names are valid. I have received notice that my application does not work with Bluetooth serial ports. While debugging this issue today, I found that the GetDefaultCommConfig() function does not return a successful value when called with the bluetooth serial port name. The GetLastError() function returns 29 (invalid parameter) in these circumstances. Is there a workaround for this problem?
回答1:
I've had a look at the serial ports on my machines with Bluetooth and can confirm that GetDefaultCommConfig() fails for virtual Serial Ports created by the Microsoft Bluetooth stack. It seems to work ok for Widcomm ports however. (I haven't tested BlueSoleil/Toshiba/etc.)
So it seems the best plan is not to use GetDefaultCommConfig() for the MSFT ports. To identify which ports are which stack, check the values under HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM, which lists the COM port name as the value. If the value name is "\Device\BtModemNNN" then it's the MSFT Bluetooth stack. (Widcomm has "\Device\BtPortNNN").
[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM]
"\\Device\\BtPort3"="COM19"
"\\Device\\BthModem2"="COM25"
Alan
回答2:
This isn't a full answer. I have found that my Windows 7 development machine quite correctly returns from GetDefaultCommConfig() for Bluetooth SPP COM ports even with using MSFT's stack (the ports show \Device\BthModem0 and \Device\BthModem1).
However, I do see GetDefaultCommConfig() failing in Windows 8.1 with a return code of 87 (returned by GetLastError()). This is identical in behaviour to COM ports that definitely don't exist.
The SPP COM ports do still work with a Hyperterminal type application but I do not know how the ports are scanned or opened in that application - I only know my application uses GetDefaultCommConfig() and its ilk from kernel32.dll and that this does not work.
Long shot and a half but I don't suppose anybody else has any input after 4 years?
来源:https://stackoverflow.com/questions/6850965/how-come-getdefaultcommconfig-doesnt-work-with-bluetooth-spp-devices