蓝牙SDK标头中的错误

时间:2012-11-19 13:56:24

标签: c sockets bluetooth

#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;
}

我在bthsdpdef.h中有很多语法和缺少类型错误,这是在microsoft sdk文件夹中。 如:

  

bthsdpdef.h(11):错误C2146:语法错误:缺少&#39 ;;&#39;在标识符&#39; LowPart&#39;之前,

     

bthsdpdef.h(11):错误C4430:缺少类型说明符 - 假设为int。注意:C ++不支持default-int

问题是什么?

2 个答案:

答案 0 :(得分:1)

在文件顶部添加以下行(在#include上方)。这为我修复了编译。

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

您的代码需要包含基本头文件。否则,当编译器到达bthsdpdef.h并看到以下内容时,它不知道类型为ULONGLONG的定义。

struct SDP_LARGE_INTEGER_16 {
    ULONGLONG LowPart;
    LONGLONG HighPart;
};

答案 1 :(得分:0)

我认为编译错误有一个暗示(我知道,这确实令人惊讶,但确实发生了。)

这些很可能是C API,但您正在编译为C ++。你的代码肯定看起来像C,所以仔细检查你的编译器调用。