I'm currently attempting to do Bluetooth device discovery with the Window Winsock API.
(我目前正在尝试使用Window Winsock API进行蓝牙设备发现。)
I am fairly new to C and C++ coding, so I apologize if I have any silly mistakes here. (我是C和C ++编码的新手,如果在这里有任何愚蠢的错误,我深表歉意。)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ws2bth.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
int main() {
int iResult;
// Initialize winsock
WSADATA wsaData;
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d
", iResult);
return 1;
}
// Create query parameters
WSAQUERYSETW querySet;
memset(&querySet, 0, sizeof(querySet));
querySet.dwSize = sizeof(querySet);
querySet.dwNameSpace = NS_BTH;
// Create flags and handle
DWORD flags = LUP_DEEP | LUP_RETURN_ALL;
HANDLE handle;
// Begin service lookup
iResult = WSALookupServiceBeginW(&querySet, flags, &handle);
if(iResult != 0) {
printf("Failed to begin service lookup: %d
", WSAGetLastError());
return 1;
}
}
I have been looking all over for examples of using WinSock to do Bluetooth device discovery, however I have been completely unable to find any.
(我一直在寻找使用WinSock进行蓝牙设备发现的示例,但是我一直找不到。)
I am certain I am simply using the wrong keywords in my search. (我确定我只是在搜索中使用了错误的关键字。)
However, when running this code it goes fine up until the actual call to WSALookupServiceBeginW()
. (但是,在运行此代码时,它将一直有效到实际调用WSALookupServiceBeginW()
为止。)
When calling this method, I get an error code of 10022 which according to the Microsoft documentation means I have passed an invalid argument. (调用此方法时,出现错误代码10022,根据Microsoft文档,这意味着我传递了无效的参数。)
However, I am unsure which argument is invalid. (但是,我不确定哪个参数无效。)
Is it my query parameters? (是我的查询参数吗?)
My flags? (我的旗帜?)
My querySet? (我的querySet?)
If anyone knows what I am doing wrong in this specific block of code or knows a good place I can find information on how to use the WinSock API, I would also greatly appreciate that.
(如果有人知道我在此特定代码块中做错了什么,或者知道一个合适的地方,我可以找到有关如何使用WinSock API的信息,我也将不胜感激。)
EDIT 1: I am not new to coding, just to C and C++ coding (and the Windows APIs in general).
(编辑1:我不是编码新手,只是C和C ++编码(和一般Windows API)。)
I wouldn't say I am an expert, but I would say I am fairly proficient in the Java programming language. (我不会说我是专家,但是我会说我非常精通Java编程语言。)
ask by Whirvis translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…