1.首先定义两个API函数指针及应用到的句柄 typedef HANDLE (WINAPI* PFGETDEVICEPOWER)(PVOID pvDevice, DWORD dwDeviceFlags, PCEDEVICE_POWER_STATE pdwState); typedef HANDLE (WINAPI* PFSETDEVICEPOWER)(PVOID pvDevice, DWORD dwDeviceFlags, CEDEVICE_POWER_STATE dwState); HANDLE g_hCoreDll = NULL; PFGETDEVICEPOWER g_pfnGetDevicePower = NULL; PFSETDEVICEPOWER g_pfnSetDevicePower = NULL; 2.得到两个API函数 g_hCoreDll = LoadLibrary(TEXT("coredll.dll"))); g_pfnGetDevicePower = (PFGETDEVICEPOWER)GetProcAddress((HMODULE)g_hCoreDll, TEXT("GetDevicePower")); g_pfnSetDevicePower = (PFSETDEVICEPOWER)GetProcAddress((HMODULE)g_hCoreDll, TEXT("SetDevicePower")); 3.使用函数。 PS:PMCLASS_NDIS_MINIPORT函数定义在pm.h中 CString cName;//这个就是设备的名称 TCHAR Names[50]; memcpy(Names,cName.GetBuffer(0),cName.GetLength()*2); Names[::_tcslen(Names) + 1] = _T('\0'); TCHAR szAdapterName[MAX_PATH]; StringCchPrintfW(szAdapterName, MAX_PATH, TEXT("%s\\%s"), PMCLASS_NDIS_MINIPORT, Names); if (ERROR_SUCCESS !=g_pfnSetDevicePower(szAdapterName, POWER_NAME, D4)) { //禁用失败 } if (ERROR_SUCCESS !=g_pfnSetDevicePower(szAdapterName, POWER_NAME, D0)) { //启动失败 } |
|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )
GMT+8, 2024-11-27 00:41
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.