XP蓝牙搜索程序无效

nonono1111 2013-03-18 08:37:44
按照bluetooth essentials for programmers这本书编写的windows XP上面的寻找蓝牙的程序,从网上下了一个差不多的,但是总是在WSALookupServicebegin()这个函数这出错,返回-1,不知道是哪里出错了,哪位大牛能给点指导!


void CMy3Dlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: Add your control notification handler code here


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();

}
...全文
86 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文详细介绍了利用Simulink进行变压器开路试验的电路连接配置与仿真实现方法,重点在于通过仿真手段还原实际电力系统中变压器在空载条件下的电气特性,从而深入理解其工作原理与性能表现。文章作为电力系统仿真系列研究的一部分,系统阐述了从电路模型搭建、参数设定、仿真运行到结果分析的完整流程,突出展示了MATLAB/Simulink在电力设备建模与教学科研中的强大功能与应用价值。; 适合人群:具备电力系统基础知识,熟悉MATLAB/Simulink仿真环境,从事电气工程、自动化及相关领域的研发人员,以及高年级本科生和研究生。; 使用场景及目标:①掌握变压器开路试验的基本原理与Simulink仿真建模的具体步骤;②通过仿真实验深入理解空载电流、铁芯损耗及励磁特性等关键参数的物理意义;③为后续开展变压器短路试验、暂态过程分析以及其他电力设备的仿真研究奠定理论与实践基础。; 阅读建议:建议结合Simulink软件动手实践,逐步构建并调试电路模型,重点关注各元件参数的设置方法与测量模块的应用技巧,同时推荐参考文中提及的其他相关仿真案例进行拓展学习,以全面提升对电力系统仿真实践的整体认知与操作能力。

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧