WinXP / MFC:蓝牙枚举:重置设备列表?

时间:2011-10-17 16:37:20

标签: mfc windows-xp bluetooth

我正在研究一组需要使用的蓝牙设备。他们有一个已知的MAC地址库,所以我可以从枚举列表中选择它们。我遇到问题让系统为我提供当前列表。

BLUETOOTH_RADIO_INFO radioInfo;
radioInfo.dwSize = sizeof(radioInfo);
HRESULT hr = ::BluetoothGetRadioInfo(hRadio, &radioInfo);

BLUETOOTH_DEVICE_SEARCH_PARAMS deviceSearchParams;
memset(&deviceSearchParams, 0, sizeof(deviceSearchParams));
deviceSearchParams.dwSize = sizeof(deviceSearchParams);
deviceSearchParams.fReturnAuthenticated = false;
deviceSearchParams.fReturnRemembered = false;
deviceSearchParams.fReturnUnknown = true;
deviceSearchParams.fReturnConnected = false;
deviceSearchParams.hRadio = hRadio;

HANDLE hDeviceFind = ::BluetoothFindFirstDevice(&deviceSearchParams, &deviceInfo); 

我遍历设备列表并挑选出已识别的单位。

似乎我必须重新运行控制面板小程序才能刷新可发现的设备,否则我会得到一个似乎是“记住”的列表(而不是本地,非配对和设备的实际设备列表)打开了。)

建议?

使用XP / VC2008 / MFC

1 个答案:

答案 0 :(得分:0)

FWIW:如果要重置列表,请使用以下代码:

WORD wVersionRequested = 0x202;
WSADATA m_data;

if ( ::WSAStartup(wVersionRequested, &m_data) == S_OK )
{
   WSAQUERYSET querySet;

   memset(&querySet, 0, sizeof(querySet));

   querySet.dwSize = sizeof(querySet);

   querySet.dwNameSpace = NS_BTH;

   HANDLE hLookup;
   DWORD flags = LUP_RETURN_NAME | LUP_CONTAINERS | LUP_RETURN_ADDR | LUP_FLUSHCACHE |      LUP_RETURN_TYPE | LUP_RETURN_BLOB | LUP_RES_SERVICE;

   int nResult = WSALookupServiceBegin(&querySet, flags, &hLookup);
   WSALookupServiceEnd(hLookup);
   WSACleanup();

   if( nResult != S_OK ) return FALSE; 
   else return TRUE;
}

return FALSE;