首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动平台 >

关于蓝牙WSALookupServiceNext()异常10050的有关问题

2012-02-22 
关于蓝牙WSALookupServiceNext()错误10050的问题各位大侠我最近初学蓝牙,准备在WIN CE平台下用SOCKET进行

关于蓝牙WSALookupServiceNext()错误10050的问题
各位大侠我最近初学蓝牙,准备在WIN CE平台下用SOCKET进行蓝牙的开发。
但是在查找设备的时候总是出错。是在WSALookupServiceNext()这一步的时候出现了错误,错误代码为10050
代码:
  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);  

是不是我还没对蓝牙进行初始化配置,还是在定制的时候没有定制好,我在定制系统的时候加了
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这串十六进制的东西。

[解决办法]
才疏学浅,没弄过蓝YA,上MSDN,有10050这个错误的信息

热点排行