如何在 Windows 上宣传蓝牙服务?
How to advertise bluetooth service on Windows?
我正在 Windows 上开发蓝牙(不是 BLE)应用程序。我需要 Windows PC 作为服务器,并通过 SDP 协议发布服务,但不知何故我很难找到合适的 API,除了这个:BluetoothSetLocalServiceInfo。文件在这里:https://docs.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 PC 上宣传蓝牙服务是否正确,如果正确,我是否正确使用了它。如果不是,什么是合适的 API 在 Windows 上发布服务?
我认为正确的API应该是WSASetService。可以在此处找到文档:https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wsasetservice。
或者,可以使用 IOCTL_BTH_SDP_SUBMIT_RECORD IOCTL,尽管我还不知道如何使用。文件在这里:https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/bthioctl/ni-bthioctl-ioctl_bth_sdp_submit_record.
我正在 Windows 上开发蓝牙(不是 BLE)应用程序。我需要 Windows PC 作为服务器,并通过 SDP 协议发布服务,但不知何故我很难找到合适的 API,除了这个:BluetoothSetLocalServiceInfo。文件在这里:https://docs.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 PC 上宣传蓝牙服务是否正确,如果正确,我是否正确使用了它。如果不是,什么是合适的 API 在 Windows 上发布服务?
我认为正确的API应该是WSASetService。可以在此处找到文档:https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wsasetservice。 或者,可以使用 IOCTL_BTH_SDP_SUBMIT_RECORD IOCTL,尽管我还不知道如何使用。文件在这里:https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/bthioctl/ni-bthioctl-ioctl_bth_sdp_submit_record.