对无线网卡信号强度提取的程序中的一点问题(附源码)
ti365 2005-07-12 04:39:42 程序功能:提取无线网卡的信号强度
问题:设备不能打开
无线网卡驱动的系统文件打不开,创建不了相关的设备hDevice
在DeviceIoControl中 参数IOCTL_GET_INFO 不知怎么定义
请各位赐教,谢谢!!
readSS.cpp
#include "StdAfx.h"
#include <stdio.h>
#include <windows.h>
#include "readSS.h"
#define __NOT_WINCE__
#ifdef __NOT_WINCE__
#define SPRINT sprintf
#define STRCPY strcpy
#define STRCAT strcat
#define STRLEN strlen
#else //! __NOT_WINCE__
#define SPRINT swprintf
#define STRCPY wcscpy
#define STRCAT wcscat
#define STRLEN wcslen
#endif //__NOT_WINCE__
#define ShowMessage(str) \
::MessageBox( NULL, TEXT(str), TEXT("Warning"),MB_OKCANCEL )
#define ShowMessageFmt(str) TCHAR lpCaption[260] ;\
SPRINT(lpCaption ,TEXT("%s") , TEXT(str) , GetLastError() ) ; \
ShowMessage(lpCaption );
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++SteP4++++++++++++++++++++++++++++++
//IoControlOpenCall(hDevice);
//++++++++++++++++++++SteP4++++++++++++++++++++++++++++++
#define IOCTL_GET_INFO 0x00000017//0x170002 //0x170002 (EX_AC_BD_CLOSE_ERR) Bd close err = %d, bd # = %d, phy mod # = %d, bd type = %d
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//此处如何定义满足要求!
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GetApInfo+++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GetApInfo+++++++++
void CreadSS::GetApInfo(/*HWND hWnd*/ )
{
HANDLE hDevice ;
//++++++++++++++++++++SteP1++++++++++++++++++++++++++++++
hDevice = CreateFile("\\\\.\\C:\\WINDOWS\\system32\\drivers\\sis162u.sys",//"\\\\?\\H:\\winnt\\system32\\drivers\\wlluc48.sys",//m_pDriverName,//driverStr,
0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
0,//NULL,
OPEN_EXISTING,
0,
0//NULL
);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 此处创建不了 hDevice;参数设置不正确。
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//C:\\WINDOWS\\system32\\drivers\\sis162u.sys
//++++++++++++++++++++SteP2++++++++++++++++++++++++++++++
if( hDevice == INVALID_HANDLE_VALUE )
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
ShowMessageFmt("Can't open the driver getApinfo [%d]" );
return ;
}
//++++++++++++++++++++SteP3++++++++++++++++++++++++++++++
memset(m_pOutBuf, 0x00, m_dwOutBuf_Size );
//++++++++++++++++++++SteP4++++++++++++++++++++++++++++++
IoControlOpenCall(hDevice);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//参数出错,hDevice;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++SteP5++++++++++++++++++++++++++++++
if ( (m_pOutBufW[0] !=0 ) | (m_pOutBufW[1] !=0 ) )
{
// Driver ready for action
do{
// Read access point scan results
//++++++++++++++++++++SteP5.A++++++++++++++++++++++++++++++
IoControlCall(hDevice, 0x820, 0x5DD);
//++++++++++++++++++++SteP5.B++++++++++++++++++++++++++++++
PrintResult(/*hWnd*/);
} while( (m_dwBytesReturned>12) && (m_dwBytesReturned<=0x5DD) ) ;
// while( (m_dwBytesReturned<=12) | (m_dwBytesReturned>0x5DD) ) ;
// Broadcast the scan request
//++++++++++++++++++++SteP6++++++++++++++++++++++++++++++
IoControlScanCall(hDevice);
}
// Tell the driver we are done.
//++++++++++++++++++++SteP7++++++++++++++++++++++++++++++
IoControlCloseCall(hDevice);
//++++++++++++++++++++SteP8++++++++++++++++++++++++++++++
CloseHandle(hDevice);
tCount++;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GetApInfo+++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GetApInfo+++++++++
//++++++++++++++++++++SteP4++++++++++++++++++++++++++++++
//IoControlOpenCall(hDevice);
//++++++++++++++++++++SteP4++++++++++++++++++++++++++++++
void CreadSS::IoControlOpenCall(HANDLE hDevice )
{
BOOL iDeviceIoControlFlag=false;
iDeviceIoControlFlag = DeviceIoControl (hDevice,
(DWORD)( IOCTL_GET_INFO ) ,//没有定义 IOCTL_GET_INFO
//IOCTL_GET_INFO,
&m_dwInBuf,sizeof(m_dwInBuf),
&m_pOutBuf,sizeof(m_pOutBuf),
&m_dwBytesReturned,
(LPOVERLAPPED)NULL
);
if( !iDeviceIoControlFlag )
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
//The LocalFree function frees the specified local memory object and invalidates its handle.
//This function is provided only for compatibility with 16-bit versions of Windows.
ShowMessageFmt("DeviceIoControl Error [%d]" );
}
}