PC程序为什么搜索不到蓝牙设备?
PC为XP SP3,ThinkPad SL400,自带有蓝牙功能,现在我在PC旁边打开手机蓝牙,使用PC的蓝牙搜索,可以搜索到手机蓝牙。
但是我自己编写的程序为什么就搜索不到呢?代码如下:
搜索到的结果一直是:
WSAStartup is OK
WSALookupServiceBegin() is OK!
WSALookupServiceNext() looks fine!
Service instance name:FHJUN2007 //这是该PC的电脑名,应该是手机的呀
Name space num:12 //应该是16(NS_BTH)吧,而不是12(NS_DNS)
Num of protocols:0
No more record found!
hLookup handle was released!
但是我自己编写的程序为什么就搜索不到呢?代码如下:
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsaData;
DWORD dwResult;
HANDLE hLookup = 0;
WSAQUERYSET lpRestrictions;
GUID guid = SVCID_HOSTNAME;
dwResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (dwResult != 0)
{
printf("Cannot startup Winsock, error code %d\n", dwResult);
exit(1);
}
else
printf("WSAStartup is OK!\n");
ZeroMemory(&lpRestrictions, sizeof(WSAQUERYSET));
lpRestrictions.dwSize = sizeof(WSAQUERYSET);
lpRestrictions.lpServiceClassId = &guid;
dwResult = WSALookupServiceBegin(&lpRestrictions, LUP_RETURN_NAME, &hLookup);
if (dwResult != SOCKET_ERROR)
{
DWORD dwLength = 0;
WSAQUERYSET * pqs = NULL;
printf("WSALookupServiceBegin() is OK!\r\n");
pqs = (WSAQUERYSET *) malloc(sizeof(WSAQUERYSET) + 100);
dwLength = sizeof(WSAQUERYSET) + 100;
do
{
if (WSALookupServiceNext(hLookup, 0, &dwLength, pqs) != 0)
{
dwResult = WSAGetLastError();
if((dwResult == WSA_E_NO_MORE) || (dwResult == WSAENOMORE))
{
printf("No more record found!\n");
break;
}
printf("WSALookupServiceNext() failed with error code %d\n", WSAGetLastError());
}
else
{
dwResult = 0;
printf("WSALookupServiceNext() looks fine!\r\n");
}
if (dwResult == WSAEFAULT)
{
if (pqs)
{
printf("Freeing pqs...\r\n");
free(pqs);
}
// Reallocate
pqs = (WSAQUERYSET *) malloc(dwLength);
if (!pqs)
{
printf("Could not allocate memory: %d\n", GetLastError());
exit(2);
}
else
{
printf("Memory allocated for pqs successfully!\r\n");
continue;
}
}
// Output it since we have it now
if ((dwResult == 0) && (pqs))
{
printf(" Service instance name: %S\n", pqs->lpszServiceInstanceName);
printf(" Name space num: %d\r\n", pqs->dwNameSpace);
printf(" Num of protocols: %d\r\n", pqs->dwNumberOfProtocols);
//printf(" Version: %d\r\n", pqs->lpVersion->dwVersion);
}
} while ((dwResult != WSA_E_NO_MORE) && (dwResult != WSAENOMORE));
// clean-up
free(pqs);
if(WSALookupServiceEnd(hLookup) == 0){
printf("hLookup handle was released!\n");
}
else{
printf("WSALookupServiceEnd(hLookup) failed with error code %d\n", WSAGetLastError());
}
}
else
{
printf("Error on WSALookupServiceBegin: %d\n", WSAGetLastError());
exit(3);
}
if(WSACleanup() == 0){
printf("WSACleanup() is OK!\n");
}
else{
printf("WSACleanup() failed with error code %d\n", WSAGetLastError());
}
printf("按回车键退出!\n");
char c = getchar();
return 0;
}
搜索到的结果一直是:
WSAStartup is OK
WSALookupServiceBegin() is OK!
WSALookupServiceNext() looks fine!
Service instance name:FHJUN2007 //这是该PC的电脑名,应该是手机的呀
Name space num:12 //应该是16(NS_BTH)吧,而不是12(NS_DNS)
Num of protocols:0
No more record found!
hLookup handle was released!
...全文
相关推荐
蓝牙大师十代机的pc程序
【蓝牙大师十代机的PC程序】是一款专为蓝牙设备设计的上位机软件,主要用于管理及控制蓝牙卡,特别是进行延期操作。在使用这款软件时,用户需要注意几个关键的知识点,以确保顺利且有效地利用其功能。
pc端的蓝牙测试工具
标题中的“pc端的蓝牙测试工具”指的是一个用于个人计算机(PC)的软件应用程序,它允许用户探索并连接到周围的蓝牙设备。这类工具通常具备基本的蓝牙设备管理功能,如扫描、查找、配对和连接蓝牙设备。
蓝牙大师PC端软件
【蓝牙大师PC端软件】是一款专为用户设计的蓝牙管理工具,它允许用户方便地复制、保存和管理蓝牙设备的相关信息。
BluetoothPcDebugger:蓝牙调试Pc端
**配置蓝牙设置**:在软件中配置蓝牙设备的相关参数,如设备地址、连接端口等。5. **连接设备**:启动蓝牙设备搜索,选择目标设备进行连接。6.
PC蓝牙通信C#代码实现
接着调用DiscoverDevices方法,该方法会在10秒内搜索到的蓝牙设备,并将这些设备信息存储在LanYa对象的列表中。


无线
