重启PPC或smartphone调用ExitWindowsEx的问题

本文介绍在不同版本的Windows Mobile操作系统上实现设备软重启的三种方法:通过KernelIoControl、SetSystemPowerState和ExitWindowsEx函数。针对不同的操作系统版本,提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自http://www.pocketpcdn.com/articles/articles.php?&atb.set(a_id)=3937&atb.set(c_id)=66&atb.perform(details)=&

以下是关于如何软启动Windows Mobile device。

关于软启动有三种方法:

1.调用KernelIoControl

(This approach was used in previous edition of this article but it has a number of disadvantages (implementing of this function is not required for OEMs and some old Pocket PC devices really miss this functionality, this function usually restricted so it could be used only in privileged mode ?now this is an issue only for Smartphones but not for Pocket PC and finally but most important buffers is not flushed so user could lost his data)

2.By SetSystemPowerState

3.使用ExitWindowsEx

第一种方法适用于老版本的Pocket PC,第二种适用于Windows Mobile 2003的操作系统,第三种方法适用于Windows Mobile 5.0以上的操作系统

code:

#include <winioctl.h>


void SoftReset();


extern "C" __declspec(dllimport) BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);

static void ResetWithExitWindows()
{
   HMODULE hModule = ::LoadLibrary(TEXT("aygshell.dll"));
   
   typedef BOOL (*ExitWindowsExFunction)(UINT uFlags, DWORD dwReserved);
   
   ExitWindowsExFunction f = (ExitWindowsExFunction)::GetProcAddress(hModule, TEXT("ExitWindowsEx"));
   
#ifndef EWX_REBOOT
#define EWX_REBOOT   2
#endif

   f(EWX_REBOOT, 0);
   
   FreeLibrary(hModule);
   
}

static void ResetWithSetSystemPowerState()
{
   typedef DWORD (*SetSystemPowerStateFunction)(LPCWSTR pwsSystemState, DWORD StateFlags, DWORD Options);
   HMODULE hModule = ::LoadLibrary(TEXT("Coredll.dll"));
   
   SetSystemPowerStateFunction f = (SetSystemPowerStateFunction)
      ::GetProcAddress(hModule, TEXT("SetSystemPowerState"));
   
#ifndef POWER_STATE_RESET
#define POWER_STATE_RESET DWORD(0x00800000)
#endif

   f(NULL, POWER_STATE_RESET, 0);
   ::FreeLibrary(hModule);
}

static void ResetWithKernelIoControl()
{
#ifndef IOCTL_HAL_REBOOT
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif

   KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}

void SoftReset()
{
   OSVERSIONINFO vi;
   memset(&vi, 0, sizeof(vi));
   vi.dwOSVersionInfoSize = sizeof(vi);
   VERIFY(GetVersionEx(&vi));
   if (vi.dwMajorVersion >= 5) {
      ResetWithExitWindows();
   } else if (vi.dwMajorVersion==4 && vi.dwMinorVersion>=20) {
      ResetWithSetSystemPowerState();
   } else {
      ResetWithKernelIoControl();
   }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值