【发布时间】:2021-06-17 02:59:20
【问题描述】:
我正在尝试构建一个 BT 应用程序。我想使用 BluetoothSetLocalServiceInfo,但收到错误 1314(客户端不持有所需的权限)。 我使用 Windows 驱动程序中的 echo 蓝牙示例。这是我修改后的代码:
DEFINE_GUID(BTHECHOSAMPLE_SVC_GUID, 0xc07508f2, 0xb970, 0x43ca, 0xb5, 0xdd, 0xcc, 0x4f, 0x23, 0x91, 0xbe, 0xf4);
wchar_t name[17] = L"BthEchoSampleSrv";
extern __declspec(selectany) const PWSTR BthEchoSampleSvcName = name;
/* fc71b33d-d528-4763-a86c-78777c7bcd7b */
DEFINE_GUID(BTHECHOSAMPLE_DEVICE_INTERFACE, 0xfc71b33d, 0xd528, 0x4763, 0xa8, 0x6c, 0x78, 0x77, 0x7c, 0x7b, 0xcd, 0x7b);
int main(){
DWORD err = ERROR_SUCCESS;
BLUETOOTH_LOCAL_SERVICE_INFO SvcInfo = { 0 };
SvcInfo.Enabled = true;
if (FAILED(StringCbCopyW(SvcInfo.szName, sizeof(SvcInfo.szName), BthEchoSampleSvcName)))
{
printf("Copying svc name failed\n");
goto exit;
}
std::cout<<"Name of the device: "<< SvcInfo.szName<<std::endl;
if (ERROR_SUCCESS != (err = BluetoothSetLocalServiceInfo(
NULL, //callee would select the first found radio
&BTHECHOSAMPLE_SVC_GUID,
0,
&SvcInfo
)))
{
printf("BluetoothSetLocalServiceInfo failed, err = %d\n", err);
goto exit;
}
exit:
return err;
}
我在命令行中运行代码(以管理员身份打开),并更改了应用程序的属性以使用管理员权限运行。我错过了什么?
【问题讨论】: