大家帮看看为什么DeviceIoControl访问OID_802_11_BSSID_LIST老是失败

joe2007max83   2011-7-1 16:16 楼主
如题,下面一段程序中,DeviceIoControl访问OID_802_11_BSSID_LIST老是失败(见下面红色),也就是说bResult一直等于0;为什么?请教牛人!!!
可能的问题出现在哪?为什么第二个DeviceIoControl失败?

#include "stdafx.h"
#include <windows.h>  
#include <winioctl.h>  
#include <string.h>  
#include <stdio.h>  
#include <IPHlpApi.h>  
#include <IPTypes.h>  
#include <ntddndis.h>


#define NUMBEROF_BSSIDS 10  

int main()
{
HANDLE hDev;
bool bResult;
DWORD junk;
unsigned char macadress[32];
  NDIS_802_11_BSSID_LIST* m_pBSSIDList;
   
m_pBSSIDList = ( NDIS_802_11_BSSID_LIST *) VirtualAlloc( NULL,
  sizeof( NDIS_802_11_BSSID_LIST)* NUMBEROF_BSSIDS,
  MEM_RESERVE | MEM_COMMIT,
  PAGE_READWRITE) ;


hDev=CreateFile(L"//./{FC1F5ED6-543B-404D-9051-FF85FC7D8161}",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hDev == INVALID_HANDLE_VALUE)
{
return (FALSE);
}
else
{  
memset( m_pBSSIDList, 0, sizeof( NDIS_802_11_BSSID_LIST)* NUMBEROF_BSSIDS);

ULONG oidcode = OID_802_11_BSSID_LIST_SCAN ; //0x0D01011A=218169626

DeviceIoControl(hDev,
IOCTL_NDIS_QUERY_GLOBAL_STATS,
(LPVOID)&oidcode,
sizeof(oidcode),
(ULONG *)NULL,
0,
&junk,
0);

  Sleep(2000);

memset( m_pBSSIDList, 0, sizeof( NDIS_802_11_BSSID_LIST)* NUMBEROF_BSSIDS);
  
oidcode = OID_802_11_BSSID_LIST; //0x0D010217=218169879
bResult= DeviceIoControl(hDev,              。。。。。。。。。。。。。就是这个DeviceIoControl失败!
IOCTL_NDIS_QUERY_GLOBAL_STATS,
&oidcode,
sizeof( oidcode),
( ULONG *) m_pBSSIDList,
sizeof( NDIS_802_11_BSSID_LIST)* NUMBEROF_BSSIDS,
&junk,
NULL);

if (bResult)
{
for (int i=0;i<m_pBSSIDList->NumberOfItems;i++)
{
int temp=i;
PNDIS_WLAN_BSSID cpSsid=m_pBSSIDList->Bssid;
while(temp!=0)
{
cpSsid=(PNDIS_WLAN_BSSID)((char *)cpSsid +cpSsid->Length);
temp--;
}
printf("%f",cpSsid->Ssid.Ssid);
printf("%d",cpSsid->Rssi);
printf((char*)macadress,"%02X-%02X-%02X-%02X-%02X-%02X",
(int*)m_pBSSIDList->Bssid.MacAddress[0],
(int*)m_pBSSIDList->Bssid.MacAddress[1],
(int*)m_pBSSIDList->Bssid.MacAddress[2],
(int*)m_pBSSIDList->Bssid.MacAddress[3],
(int*)m_pBSSIDList->Bssid.MacAddress[4],
(int*)m_pBSSIDList->Bssid.MacAddress[5]);
}
}
printf("failed");
  CloseHandle(hDev);
  getchar();
}
}

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复