我正在Windows上开发蓝牙(而不是BLE)应用程序。我需要Windows作为服务器,并通过SDP协议为服务做广告,但不知怎的,我几乎找不到合适的API,除了这个: BluetoothSetLocalServiceInfo。文档在这里:https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothsetlocalserviceinfo。但是,我目前仍然无法成功地使用它来发布其他设备可以使用以下代码检测到的服务,尽管它返回了ERROR_SUCCESS。
void BluetoothManager::RegisterServiceBtAPI(){
BLUETOOTH_LOCAL_SERVICE_INFO_STRUCT serviceInfo;
serviceInfo.Enabled = TRUE;
BLUETOOTH_ADDRESS btAddress;
QUtils::CharArray2BTH_ADDR(btServerAddress.toString().toStdString().c_str(), &btAddress.ullLong);
serviceInfo.btAddr = btAddress;
QString("ServiceName").toWCharArray(serviceInfo.szName);
QString("DeviceName").toWCharArray(serviceInfo.szDeviceString);
QUtils::EnableSpecificPrivilege(SE_LOAD_DRIVER_NAME);
//{00001101-0000-1000-8000-00805F9B34FB};
const GUID serviceGUID = { 0x00001101, 0x0000, 0x0000, { 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } };
int result = BluetoothSetLocalServiceInfo(
NULL, &serviceGUID, 0, &serviceInfo
);
if(result!=ERROR_SUCCESS){
emit ShowDebug(QString("BluetoothSetLocalServiceInfo failed with error: %1").arg(result));
}else{
emit ShowDebug(QString("BluetoothSetLocalServiceInfo succeeded."));
}
}
我想知道用这种方法在Windows上宣传蓝牙服务是否正确,如果是,我是否正确地使用了它。如果不是,在Windows上发布服务的合适API是什么?
发布于 2021-12-24 19:09:22
我认为正确的API应该是WSASetService。文档可以在这里找到:https://learn.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wsasetservice。或者,可以使用IOCTL_BTH_SDP_SUBMIT_RECORD IOCTL,尽管我还不知道如何使用。文档在这里:https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/bthioctl/ni-bthioctl-ioctl_bth_sdp_submit_record。
https://stackoverflow.com/questions/70466390
复制相似问题