如题,下面一段程序中,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();
}
}