How come GetDefaultCommConfig() Doesn't Work with Bluetooth SPP Devices?

本小妞迷上赌 提交于 2020-01-14 06:31:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!