我在VS 2008的工作與安裝了Windows SDK 7.1 BluetoothRegisterForAuthentication不起作用。 要將BT設備與我的應用程序配對,我使用Windows BT API。 我使用的API是BluetoothRegisterForAuthentication和BluetoothAuthenticateDevice。MFC藍牙:
我整理的Windows XP應用程序,它工作正常的操作系統。 當我在Windows 7機器上運行應用程序時,會發生問題。 BluetoothRegisterForAuthentication返回錯誤代碼1783是RPC_X_BAD_STUB_DATA。
如果我編譯在Windows 7上相同的代碼,它工作正常與操作系統,但它未能啓動應用程序。
同樣的事情發生,如果我運行應用程序,這是與Windows7的編制,在Windows 8
我不只是瞭解Windows(在我的情況VS 2008)操作系統和開發工具的工作原理是這樣。
請給我任何意見。我需要使應用程序在Windows XP,Vista,7和8上運行。並且我正在考慮爲每個操作系統構建多個exe文件。 Belows是我的代碼。
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 %d\n", dwRet);
}
dwRet = BluetoothAuthenticateDevice(NULL, NULL, &btdi, L"0000", 4);
if(dwRet != ERROR_SUCCESS)
{
TRACE("BluetoothAuthenticateDevice ret %d\n", dwRet);
}
Sleep(1000);
return 0;
}