织梦CMS - 轻松建站从此开始!

罗索

编程实现查找并显示Windows Mobile下蓝牙设备

落鹤生 发布于 2010-07-07 22:00 点击:次 
一段实现查找并显示蓝牙设备的代码。PerformInquiry (BT device Inquiry) Purpose: Performs a device inquiry displays the device name in a user interface.
TAG:

  1. //------------------------------------------------------------------------ 
  2. // Function: PerformInquiry (BT device Inquiry) 
  3. // Purpose: Performs a device inquiry displays the device name in a user interface. 
  4. // Note: This function does not include a call to WSAStartup as described 
  5. //       in the procedure. 
  6. //       This sample has not been tested and is not intended for production use. 
  7. //------------------------------------------------------------------------ 
  8. #define MAX_NAME 248 
  9. static BOOL PerformInquiry() 
  10. WSAQUERYSET wsaq; 
  11. HANDLE hLookup; 
  12. union { 
  13.     CHAR buf[5000]; 
  14.     double __unused; // ensure proper alignment 
  15. }; 
  16. LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf; 
  17. DWORD dwSize = sizeof(buf); 
  18. BOOL bHaveName; 
  19. ZeroMemory(&wsaq, sizeof(wsaq)); 
  20. wsaq.dwSize = sizeof(wsaq); 
  21. wsaq.dwNameSpace = NS_BTH; 
  22. wsaq.lpcsaBuffer = NULL; 
  23. if (ERROR_SUCCESS != WSALookupServiceBegin (&wsaq, LUP_CONTAINERS, &hLookup)) 
  24.     wprintf(L"WSALookupServiceBegin failed %d\r\n", GetLastError()); 
  25.     return FALSE; 
  26. ZeroMemory(pwsaResults, sizeof(WSAQUERYSET)); 
  27. pwsaResults->dwSize = sizeof(WSAQUERYSET); 
  28. pwsaResults->dwNameSpace = NS_BTH; 
  29. pwsaResults->lpBlob = NULL; 
  30. while (ERROR_SUCCESS == WSALookupServiceNext (hLookup,
  31.  LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults)) 
  32.     ASSERT (pwsaResults->dwNumberOfCsAddrs == 1); 
  33.     BT_ADDR b = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr; 
  34.     bHaveName = pwsaResults->lpszServiceInstanceName &&
  35.  *(pwsaResults->lpszServiceInstanceName); 
  36.     wprintf (L"%s%s%04x%08x%s\n", bHaveName ? pwsaResults->lpszServiceInstanceName : L""
  37.     bHaveName ? L"(" : L"", GET_NAP(b), GET_SAP(b), bHaveName ? L")" : L""); 
  38. WSALookupServiceEnd(hLookup); 
  39. return TRUE; 

 

(zj41342626)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201007/9796.html]
本文出处:百度博客 作者:zj41342626
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容