Wince擷取Wifi的裝置名稱、串連狀態和訊號強度

來源:互聯網
上載者:User
Note:需CE4.0或更高版本(相容NDIS5.1)支援
一、加入標頭檔
#include <winioctl.h>
#include <ntddndis.h>
#include <nuiouser.h>
二、Attach to NDISUIO
HANDLE hNdis = ::CreateFile( NDISUIO_DEVICE_NAME, GENERIC_ALL, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
(HANDLE)INVALID_HANDLE_VALUE );

三、擷取裝置名稱

UCHAR                  cbQueryBuffer[ 1024 ];
PNDISUIO_QUERY_BINDING pQueryBinding;
DWORD dwBytesReturned = 0;

pQueryBinding = (PNDISUIO_QUERY_BINDING)&cbQueryBuffer[ 0 ];
pQueryBinding->BindingIndex = 0;

if ( ::DeviceIoControl( hNdis,
IOCTL_NDISUIO_QUERY_BINDING,
(LPVOID)&cbQueryBuffer[ 0 ],
sizeof(NDISUIO_QUERY_BINDING),
(LPVOID)&cbQueryBuffer[ 0 ],
sizeof(cbQueryBuffer),
&dwBytesReturned,
NULL ) == TRUE )
{
TCHAR* pDeviceName = (TCHAR*)( cbQueryBuffer + pQueryBinding->DeviceNameOffset );
}

 

四、檢測串連狀態

NIC_STATISTICS nicStatistics = { 0 };
DWORD dwBytesReturned = 0;
BOOL bConnected = FALSE;

nicStatistics.ptcDeviceName = pDeviceName;

if ( ::DeviceIoControl( hNdis,
IOCTL_NDISUIO_NIC_STATISTICS,
NULL,
0,
&nicStatistics,
sizeof(NIC_STATISTICS),
&dwBytesReturned,
NULL ) == TRUE )
{
bConnected = ( nicStatistics.MediaState == MEDIA_STATE_CONNECTED );
}

五、擷取訊號強度

// example.
// < -90 : No Signal
// < -81 : Very Low
// < -71 : Low
// < -67 : Good
// < -57 : Very Good
// ... : Excellent

NDISUIO_QUERY_OID ndisQueryOid = { 0 };
DWORD dwBytesReturned = 0;
int nDb = 0;

ndisQueryOid.Oid = OID_802_11_RSSI;
ndisQueryOid.ptcDeviceName = pDeviceName;

if ( ::DeviceIoControl( hNdis,
IOCTL_NDISUIO_QUERY_OID_VALUE,
(LPVOID)&ndisQueryOid,
sizeof(ndisQueryOid),
(LPVOID)&ndisQueryOid,
sizeof(ndisQueryOid),
&dwBytesReturned,
NULL ) == TRUE )
{
::CopyMemory( &nDb, &ndisQueryOid.Data[ 0 ], sizeof(ULONG) );
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.