首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Windows上为蓝牙服务做广告?

如何在Windows上为蓝牙服务做广告?
EN

Stack Overflow用户
提问于 2021-12-23 19:01:47
回答 1查看 183关注 0票数 0

我正在Windows上开发蓝牙(而不是BLE)应用程序。我需要Windows作为服务器,并通过SDP协议为服务做广告,但不知怎的,我几乎找不到合适的API,除了这个: BluetoothSetLocalServiceInfo。文档在这里:https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothsetlocalserviceinfo。但是,我目前仍然无法成功地使用它来发布其他设备可以使用以下代码检测到的服务,尽管它返回了ERROR_SUCCESS。

代码语言:javascript
运行
复制
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是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70466390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档