关于蓝牙WSALookupServiceNext()错误10050的问题
[复制链接]
各位大侠我最近初学蓝牙,准备在WIN CE 5.0 平台下用SOCKET进行蓝牙的开发。
但是在查找设备的时候总是出错。是在WSALookupServiceNext()这一步的时候出现了错误,错误代码为10050 好像是没有找到蓝牙设备,用CE里的例子试也是出现错误代码10050。
是不是我还没对蓝牙进行初始化配置,还是在定制的时候没有定制好,我在定制系统的时候加了
Bluetooth Stack with lnteqrated UART Driver 和 Bluetooth Stack with lnteqrated CSR Chipset Driver 和 Bluetooth Stack with Universal Loadable Driver 这三项了,芯片是CSR公司的BC4,跟COM1:只连接TX和RX两根,用串口助手读的时候是不断的读到:C0 40 41 00 7E DA DC DE DE A9 7A C0这串十六进制的东西。
代码:
1初始化:
err = WSAStartup(MAKEWORD(2,2),&wsd);
if(err!=0)
{
AfxMessageBox(L"SOCKET ERROR!");
}
if(LOBYTE(wsd.wVersion)!=2||HIBYTE(wsd.wVersion)!=2)
{
WSACleanup();
AfxMessageBox(L"SOCKET 2.2 ERROR!");
}
2查找设备:
ZeroMemory(&wsaq, sizeof(wsaq));
wsaq.dwSize = sizeof(wsaq);
wsaq.dwNameSpace = NS_BTH;
wsaq.lpcsaBuffer = NULL;
if (ERROR_SUCCESS != WSALookupServiceBegin (&wsaq, LUP_CONTAINERS, &hLookup))
{
a = GetLastError();
aa.Format (L"WSALookupServiceBegin error num %d",a);
AfxMessageBox(aa);
}
ZeroMemory(pwsaResults, sizeof(WSAQUERYSET));
pwsaResults->dwSize = sizeof(WSAQUERYSET);
pwsaResults->dwNameSpace = NS_BTH;
pwsaResults->lpBlob = NULL;
if(m_pStart)
{
for(m_pCurrentDevice=m_pStart;m_pCurrentDevice;)
{
DeviceList *temp=m_pCurrentDevice;
m_pCurrentDevice=m_pCurrentDevice->NextDevice;
free(temp);
}
}
m_pEnd=m_pStart=NULL;
m_iNumDevices=0;
while (true)
{
//在这里就出错了,错误代码10050,好像是没找到设备
if(WSALookupServiceNext (hLookup, LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults)!=ERROR_SUCCESS)
{
a = GetLastError();
aa.Format (L"WSALookupServiceBegin error num %d",a);
AfxMessageBox(aa);
/////////////////////////////////
for(int iiii=m_ListBox_Content.GetCount(); iiii>0; iiii--)
m_ListBox_Content.DeleteString(iiii-1);
de=L"CAN NOT FIND DEVICES";
bc=L"Devices Num : ";
ab.Format(L"%d",m_iNumDevices);
cd=bc+ab;
m_ListBox_Content.InsertString(0,de);
m_ListBox_Content.InsertString(1,cd);
//m_ListBox_Content.AddString(bc);
////////////////////////////
break;
}
ASSERT (pwsaResults->dwNumberOfCsAddrs == 1);
tempDevice=(DeviceList*)malloc(sizeof(DeviceList));
tempDevice->NextDevice=NULL;
if(m_pStart==NULL)
{
m_pStart = tempDevice;
m_pEnd=m_pStart;
}
else
{
m_pEnd->NextDevice =tempDevice;
m_pEnd=tempDevice;
///////////////////////////////////////
for(int iii=m_ListBox_Content.GetCount(); iii>0; iii--)
m_ListBox_Content.DeleteString(iii-1);
de=L"SCAN DEVICES";
bc=L"Devices Name : ";
ab.Format(L"%S",tempDevice->bthName);
cd=bc+ab;
m_ListBox_Content.InsertString(0,ab);
m_ListBox_Content.AddString(bc);
//////////////////////////////////////////
}
m_iNumDevices++;
m_pEnd->bthAddress = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;
de=L"SCAN DEVICES";
bc=L"Devices Num : ";
ab.Format(L"%d",m_iNumDevices);
cd=bc+ab;
m_ListBox_Content.AddString(cd);
}
WSALookupServiceEnd(hLookup);
高手们,快出现吧!