如何通过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 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
- ¥20 matlab yalmip kkt 双层优化问题
- ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
- ¥88 实在没有想法,需要个思路
- ¥15 MATLAB报错输入参数太多