Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么BluetoothSetLocalServiceInfo抛出错误1314?_C++_Windows_Bluetooth - Fatal编程技术网

C++ 为什么BluetoothSetLocalServiceInfo抛出错误1314?

C++ 为什么BluetoothSetLocalServiceInfo抛出错误1314?,c++,windows,bluetooth,C++,Windows,Bluetooth,我一直在尝试构建一个BT应用程序。我想使用BluetoothSetLocalServiceInfo,但出现错误1314(客户端不拥有所需的权限)。 我使用windows驱动程序中的echo bluetooth示例。这是我修改过的代码: DEFINE_GUID(BTHECHOSAMPLE_SVC_GUID, 0xc07508f2, 0xb970, 0x43ca, 0xb5, 0xdd, 0xcc, 0x4f, 0x23, 0x91, 0xbe, 0xf4); wchar_t name[17] =

我一直在尝试构建一个BT应用程序。我想使用BluetoothSetLocalServiceInfo,但出现错误1314(客户端不拥有所需的权限)。 我使用windows驱动程序中的echo bluetooth示例。这是我修改过的代码:

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;
}
DEFINE_GUID(b样本SVC_GUID,0xc07508f2,0xb970,0x43ca,0xb5,0xdd,0xcc,0x4f,0x23,0x91,0xbe,0xf4);
wchar_t name[17]=L“b该样本为V”;
extern uuu declspec(selectany)const PWSTR b hechosamplesvcname=name;
/*fc71b33d-d528-4763-a86c-78777c7bcd7b*/
定义GUID(b样本设备接口,0xfc71b33d、0xd528、0x4763、0xa8、0x6c、0x78、0x77、0x7c、0x7b、0xcd、0x7b);
int main(){
DWORD err=错误\成功;
BLUETOOTH_LOCAL_SERVICE_INFO SvcInfo={0};
SvcInfo.Enabled=true;
if(失败(StringCbCopyW(SvcInfo.szName,sizeof(SvcInfo.szName),BthEchoSampleSvcName)))
{
printf(“复制svc名称失败\n”);
转到出口;
}

std::cout错误1314是
错误权限未持有的
。根据文档:

BluetoothSetLocalServiceInfo
函数返回以下值:

状态\特权\未\持有
调用方没有所需的权限。有关如何提升权限的信息,请参阅备注部分

评论说:

警告
调用
BluetoothSetLocalServiceInfo
的进程必须具有
SE\u LOAD\u DRIVER\u NAME
权限。
在系统或管理员上下文中运行的进程可以使用SDK和函数提升其权限。有关此功能的更多信息,请参阅

因此,这意味着:

  • 运行您的应用程序的用户帐户根本没有该权限
  • 您的应用程序未通过
    AdjustTokenPrivileges()
    启用权限
本文档提供了启用
SE\u LOAD\u DRIVER\u NAME
权限的示例:

安装应用程序必须调用用户模式API
BluetoothSetLocalServiceInfo
。但是,在应用程序调用此API之前,应用程序必须具有
SE\u LOAD\u DRIVER\u NAME
安全权限。下面的代码示例演示了如何获得此权限。注意,该示例未演示错误或处理

handleproctoken;
路易斯·路易斯;
令牌特权;
OpenProcessToken(GetCurrentProcess()、TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY和procToken);
LookupPrivilegeValue(NULL、SE\u LOAD\u DRIVER\u NAME和luid);
Tp.privilegecont=1;
Tp.privileges[0]。Luid=Luid;
Tp.Privileges[0]。Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(procToken,FALSE,&tp,sizeof(TOKEN\u PRIVILEGES),(PTOKEN\u PRIVILEGES)NULL,(PDWORD)NULL)

有关更多详细信息,请参阅MSDN上的和。

错误1314是
错误权限未保留。
。根据文档:

BluetoothSetLocalServiceInfo
函数返回以下值:

状态\特权\未\持有
调用方没有所需的权限。有关如何提升权限的信息,请参阅备注部分

评论说:

警告
调用
BluetoothSetLocalServiceInfo
的进程必须具有
SE\u LOAD\u DRIVER\u NAME
权限。
在系统或管理员上下文中运行的进程可以使用SDK和函数提升其权限。有关此功能的更多信息,请参阅

因此,这意味着:

  • 运行您的应用程序的用户帐户根本没有该权限
  • 您的应用程序未通过
    AdjustTokenPrivileges()
    启用权限
本文档提供了启用
SE\u LOAD\u DRIVER\u NAME
权限的示例:

安装应用程序必须调用用户模式API
BluetoothSetLocalServiceInfo
。但是,在应用程序调用此API之前,应用程序必须具有
SE\u LOAD\u DRIVER\u NAME
安全权限。下面的代码示例演示了如何获得此权限。注意,该示例未演示错误或处理

handleproctoken;
路易斯·路易斯;
令牌特权;
OpenProcessToken(GetCurrentProcess()、TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY和procToken);
LookupPrivilegeValue(NULL、SE\u LOAD\u DRIVER\u NAME和luid);
Tp.privilegecont=1;
Tp.privileges[0]。Luid=Luid;
Tp.Privileges[0]。Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(procToken,FALSE,&tp,sizeof(TOKEN\u PRIVILEGES),(PTOKEN\u PRIVILEGES)NULL,(PDWORD)NULL)

有关更多详细信息,请参阅MSDN上的和。

当您是新手时,这很容易错过。我必须更加小心。太好了!谢谢!这解决了所有问题!当您是新手时,这很容易错过。我必须更加小心。太好了!谢谢!这解决了所有问题!