MFC 蓝牙:蓝牙注册身份验证不起作用



我使用的是安装了Windows SDK 7.1的VS 2008。为了将BT设备与我的应用程序配对,我使用Windows BT API。我使用的API是BluetoothRegisterForAuthentication和BluetoothAuthenticateDevice。

我在WindowsXP上编译了这个应用程序,它在操作系统上运行良好。当我在Windows7机器上运行应用程序时,就会出现问题。BluetoothRegisterForAuthentication返回错误代码1783,该错误代码为RPC_X_BAD_STUB_DATA。

如果我在Windows7上编译相同的代码,它在操作系统中运行良好,但无法启动应用程序。

如果我在Windows8上运行使用Windows7编译的应用程序,也会发生同样的情况。

我不明白Windows操作系统和开发工具(在我的例子中是VS2008)是这样工作的。

请给我一些建议。我需要让应用程序在WindowsXP、Vista、7和8上运行。我正在考虑为每个操作系统构建多个exe文件。亲爱的是我的密码。

bool BluetoothAuthCallback(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO  pDeviceInfo)
{
DWORD dwRet;
CLogFile * m_pLog = CLogFile::getInstance();
dwRet = BluetoothSendAuthenticationResponse(NULL, pDeviceInfo, L"0000");
if(dwRet != ERROR_SUCCESS)
{
    return 1;
}
return 1;
}
int pairBluetooth(BTH_ADDR bthAddr)
{
CLogFile * m_pLog = CLogFile::getInstance();
SOCKADDR_BTH sa = { 0 };
int sa_len = sizeof(sa);
DWORD dwRet;
BLUETOOTH_DEVICE_INFO  btdi = {0};
HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle = 0;
btdi.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
btdi.Address.ullLong = bthAddr;
btdi.ulClassofDevice = 0;
btdi.fConnected = false;
btdi.fRemembered = false;
btdi.fAuthenticated = false;
dwRet = BluetoothRegisterForAuthentication(&btdi, &hRegHandle, (PFN_AUTHENTICATION_CALLBACK)&BluetoothAuthCallback, NULL);
if(dwRet != ERROR_SUCCESS)
{
    TRACE("BluetoothRegisterForAuthentication ret %dn", dwRet);
}
dwRet = BluetoothAuthenticateDevice(NULL, NULL, &btdi, L"0000", 4);
if(dwRet != ERROR_SUCCESS)
{
    TRACE("BluetoothAuthenticateDevice ret %dn", dwRet);
}
Sleep(1000);
return 0;
}

构建安装包是我的错。该包包括bt相关的系统文件。事实上有一条警告信息,但我只是忽略了它。只要从软件包中删除该文件,它就可以与其他操作系统配合使用。

最新更新