#include <Bthsdpdef.h>
#include <BluetoothAPIs.h>
#include <Winsock2.h>
#include <Ws2bth.h>
#include <stdio.h>
#pragma comment(lib, "Bthprops.lib")
int main(void){
WSADATA wsaData;
int err;
DWORD qs_len;
WSAQUERYSET *qs;
DWORD flags;
HANDLE lphLookup;
int iRet;
char buff[4096];
LPWSAQUERYSET pwsaResult = (LPWSAQUERYSET) buff;
DWORD buffLen = sizeof(buff);
BTH_ADDR result;
WORD wVersionRquested = MAKEWORD(2,2);
err = WSAStartup(wVersionRquested, &wsaData); //Statrup function
if(err != 0){
printf("WSAStartup failed");
return 1;
}
qs_len = sizeof(WSAQUERYSET);
qs = (WSAQUERYSET *) malloc(qs_len); // Save memory for WSAQUERYSET structere
ZeroMemory(qs, qs_len); //zero WSAQUERYSET out
qs->dwSize = sizeof(WSAQUERYSET);
qs->dwNameSpace = NS_BTH;
qs->lpcsaBuffer = NULL;
flags = LUP_CONTAINERS | LUP_FLUSHCACHE | LUP_RETURN_NAME | LUP_RETURN_ADDR; //details of the device discovery
iRet = WSALookupServiceBegin(qs, flags, &lphLookup);
if(iRet == ERROR_SUCCESS){
printf("WSALookupServiceBegin failed");
return 1;
}
printf("\r\n\t\t\t\tScanning...");
ZeroMemory(pwsaResult, sizeof(LPWSAQUERYSET));
pwsaResult->dwSize = sizeof(WSAQUERYSET);
pwsaResult->dwNameSpace = NS_BTH;
pwsaResult->lpBlob = NULL;
while(WSALookupServiceNext(lphLookup, flags, &buffLen, pwsaResult) != ERROR_SUCCESS){
result = ((BTH_ADDR)qs->lpcsaBuffer->RemoteAddr.lpSockaddr);
WSAAddressToString(qs->lpcsaBuffer->RemoteAddr.lpSockaddr, sizeof(SOCKADDR_BTH), NULL, (LPWSTR)buff, &buffLen);
printf("Found: %s - %s", buff, qs->lpszServiceInstanceName);
}
WSALookupServiceEnd(lphLookup);
free(qs);
WSACleanup();
return 0;
}
I got alot of syntax and missing type errors in bthsdpdef.h which is in microsoft sdk folder.
such as:
bthsdpdef.h(11): error C2146: syntax error : missing ‘;’ before identifier ‘LowPart’,
bthsdpdef.h(11): error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
what’s the problem?
Add the following lines at the top of your file (above your #include’s). That fixes the compilation for me.
Your code needs to include the base header file(s). Otherwise when the compiler comes to bthsdpdef.h and sees the following it does not know the definition of type ULONGLONG.