1
#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?

2 Answers 2

1

Add the following lines at the top of your file (above your #include's). That fixes the compilation for me.

#define WIN32_LEAN_AND_MEAN 1 // Don't include Winsock v1
#include <windows.h>
#include <stdlib.h>
#pragma comment(lib, "ws2_32.lib")

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.

struct SDP_LARGE_INTEGER_16 {
    ULONGLONG LowPart;
    LONGLONG HighPart;
};
0
0

I think there's a hint in the compiler error (I know, that's surprising but it really happens).

These are very probably C APIs, but you're compiling as C++. Your code certainly looks like C though, so double-check your compiler invocation.

1
  • I changed the compilation propreties in properties -> c/c++ ->advanced -> compile as C and still there is errors :(
    – programmer
    Nov 20, 2012 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.