#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;
}
我在 microsoft sdk 文件夹中的 bthsdpdef.h 中有很多语法和缺少类型错误。如:
bthsdpdef.h(11):错误 C2146:语法错误:缺少 ';' 在标识符“LowPart”之前,
bthsdpdef.h(11):错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认整数
有什么问题?