[置頂]WINCE 6.0 WIFIコードの無効化と有効化
3248 ワード
以下のコードはどのようにWINCE 6.0の下でWIFIを無効にして有効にするかを実現して、効果はコントロールパネルのネットワーク接続で手動で無効にして有効にすることに相当して、本人がテストしたWIFIはGH 381で、SDIO 86881
WIFIコードの無効化
WIFIの有効化
WIFIコードの無効化
int __stdcall DisableWifi()
{
HANDLE hNdisPwr;
NDISPWR_SAVEPOWERSTATE SavePowerState;
TCHAR multiSz[257];
DWORD cbBuffer = sizeof(multiSz);
StringCchCopy(multiSz, (cbBuffer / sizeof(TCHAR))-2, _T("SDIO86881"));
hNdisPwr = CreateFile(
(PTCHAR)NDISPWR_DEVICE_NAME, // Object name.
0x00, // Desired access.
0x00, // Share Mode.
NULL, // Security Attr
OPEN_EXISTING, // Creation Disposition.
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, // Flag and Attributes..
(HANDLE)INVALID_HANDLE_VALUE);
if (hNdisPwr != INVALID_HANDLE_VALUE)
{
SavePowerState.pwcAdapterName = _T("SDIO86881");
//
// If it is currently enabled, set the power level to D4.
//
SavePowerState.CePowerState = D4;
BOOL result=DeviceIoControl(
hNdisPwr,
IOCTL_NPW_SAVE_POWER_STATE,
&SavePowerState,
sizeof(NDISPWR_SAVEPOWERSTATE),
NULL,
0x00,
NULL,
NULL);
CloseHandle(hNdisPwr);
if(result!=TRUE)
return -1;
}
else
{
RETAILMSG (1,
(TEXT("hNdisPwr is INVALID_HANDLE_VALUE\r
")));
return -1;
}
SetDevicePower(_T("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\SDIO86881"), POWER_NAME, D4);
multiSz[::_tcslen(multiSz)+1] = _T('\0'); // Multi sz needs an extra null
BOOL result1=DoNdisIOControl(
IOCTL_NDIS_UNBIND_ADAPTER,
multiSz,
(_tcslen(multiSz)+2) * sizeof(TCHAR),
NULL,
NULL);
if(result1!=TRUE)
return -1;
return 0;
}
WIFIの有効化
int __stdcall EnableWifi()
{
HANDLE hNdisPwr;
NDISPWR_SAVEPOWERSTATE SavePowerState;
TCHAR multiSz[257];
DWORD cbBuffer = sizeof(multiSz);
StringCchCopy(multiSz, (cbBuffer / sizeof(TCHAR))-2, _T("SDIO86881"));
hNdisPwr = CreateFile(
(PTCHAR)NDISPWR_DEVICE_NAME, // Object name.
0x00, // Desired access.
0x00, // Share Mode.
NULL, // Security Attr
OPEN_EXISTING, // Creation Disposition.
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, // Flag and Attributes..
(HANDLE)INVALID_HANDLE_VALUE);
if (hNdisPwr != INVALID_HANDLE_VALUE)
{
SavePowerState.pwcAdapterName = _T("SDIO86881");
//
// If it is currently enabled, set the power level to D4.
//
SavePowerState.CePowerState = PwrDeviceUnspecified;
BOOL result=DeviceIoControl(
hNdisPwr,
IOCTL_NPW_SAVE_POWER_STATE,
&SavePowerState,
sizeof(NDISPWR_SAVEPOWERSTATE),
NULL,
0x00,
NULL,
NULL);
CloseHandle(hNdisPwr);
if(result!=TRUE)
return -1;
}
else
{
return -1;
}
SetDevicePower(_T("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\SDIO86881"), POWER_NAME, PwrDeviceUnspecified);
multiSz[::_tcslen(multiSz)+1] = _T('\0'); // Multi sz needs an extra null
BOOL result1=DoNdisIOControl(
IOCTL_NDIS_BIND_ADAPTER,
multiSz,
(_tcslen(multiSz)+2) * sizeof(TCHAR),
NULL,
NULL);
if(result1!=TRUE)
return -1;
return 0;
}