Hi, I have been trying to create a simple C++ porgram to scan for bluetooth devices and retrieve/store the MAC addresses from them. I found this code in an old book form the library, and want to know how and if I can use it.


Code:
void CredDlg::Discover()
{
    devices.clear();
    
    WSADATA data;

    WSAStartup(MAKEWORD( 2, 2 ),&data);
    DWORD error1 = GetLastError();
    
    WSAQUERYSET querySet;

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

    querySet.dwNameSpace = NS_BTH;

    querySet.dwSize = sizeof(querySet);

    HANDLE hLookup;

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

    int rc = WSALookupServiceBegin(&querySet,flags,&hLookup);
    error1 = WSAGetLastError();

    PBYTE pOut = (PBYTE)LocalAlloc(LPTR,16384);

    WSAQUERYSET *pQueryResult = (WSAQUERYSET *)pOut;
    DWORD buffer = 16384;

    while(true)
    {
    rc = WSALookupServiceNext(hLookup,flags,&buffer,pQueryResult);
    if (rc == SOCKET_ERROR)
        break;
    SOCKADDR_BTH *pbta = 0;
    pbta = (SOCKADDR_BTH*)pQueryResult->lpcsaBuffer->RemoteAddr.lpSockaddr;
    long classOfDevice = pQueryResult->lpServiceClassId->Data1;
    BTDevice device = BTDevice(pbta->btAddr, pQueryResult->lpszServiceInstanceName,classOfDevice);
    devices.push_back (device);
    }

    WSALookupServiceEnd(hLookup);
    LocalFree(pOut);
}
Thanx!

also...does anyone know how this bit of code works?