qq_21314563 2018-04-17 02:17 采纳率: 0%
浏览 4114
已结题

windows 蓝牙 API使用

如何通过BluetoothAuthenticateDeviceEx配对蓝牙鼠标,回调函数里面怎么写,有没有对应的demo或者示例代码看看?

  • 写回答

1条回答 默认 最新

  • qq_40250105 2018-04-17 02:49
    关注

    1。 配对代码
    BOOL CBluetooth::BtSocketAuthenticate(char *szAddr)
    {
    SOCKADDR_BTH sa = { 0 };
    int sa_len = sizeof(sa);
    DWORD dwRet;
    BLUETOOTH_DEVICE_INFO btdi = { 0 };
    HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle = 0;

    // initialize windows sockets
    WORD wVersionRequested;
    WSADATA wsaData;
    wVersionRequested = MAKEWORD(2, 0);
    if (WSAStartup(wVersionRequested, &wsaData) != 0) {
        return FALSE;
    }
    
    dwRet = BluetoothRegisterForAuthenticationEx(&m_device.bdi, &hRegHandle, &BluetoothAuthCallback, NULL);
    if (dwRet != ERROR_SUCCESS)
    {
        return FALSE;
    }
    
    if ( m_device.bdi.fAuthenticated ) 
    {   
        return TRUE;    // 已经配对了
    }
    
    DWORD status = BluetoothUpdateDeviceRecord ( &m_device.bdi );
    if ( ERROR_SUCCESS != status )
        return FALSE;
    
    // authenticate device (will call authentication callback)
    AUTHENTICATION_REQUIREMENTS authreqs = MITMProtectionRequired ;
    dwRet = BluetoothAuthenticateDeviceEx(NULL, m_radio.hRadio , &m_device.bdi, NULL, authreqs);
    

    }
    2.回调函数
    BOOL CALLBACK BluetoothAuthCallback(LPVOID pvParam, PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS pAuthCallbackParams)
    {
    DWORD dwRet;

    BLUETOOTH_AUTHENTICATE_RESPONSE AuthRes;
    AuthRes.authMethod = pAuthCallbackParams->authenticationMethod;
    
    AuthRes.bthAddressRemote = pAuthCallbackParams->deviceInfo.Address;
    AuthRes.negativeResponse = FALSE;
    AuthRes.numericCompInfo.NumericValue = pAuthCallbackParams->Numeric_Value;
    
    // Send authentication response to authenticate device
    dwRet = BluetoothSendAuthenticationResponseEx(NULL, &AuthRes);
    

    }
    //正在测试,可能会有点小bug,一人计短,一起研究

    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?