资源描述:
《wince的定时关机驱动》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、wince的定时关机驱动2009-06-0220:59以前平台的定时关机是利用wince自带的定时休眠部分代码实现的,同事老是说定时关机时间不准确,所以花了点时间,写了个简单的驱动。具体看下面的代码:#include#include"s2410.h"//#include//try#defineMAXACTIVITYTIMEOUT (0xFFFFFFFF/1000)//insecondsstaticHANDLEgThread;voidExitWince(){ //关机
2、 staticvolatileIOPreg*v_pIOPregs; v_pIOPregs=(volatileIOPreg*)IOP_BASE; v_pIOPregs->rGPBCON&=~(3<<4); v_pIOPregs->rGPBCON
3、=(1<<4); v_pIOPregs->rGPBDAT&=~(1<<2); Sleep(15); v_pIOPregs->rGPBDAT
4、=(1<<2);}BOOLGetAutoPowerOffTime(BYTE*Buffer){ HKEYhResult; LON
5、GlRet; LPWSTRlpSubKey=_T("\System\CurrentControlSet\Control\Power\Timeouts"); DWORDsize=sizeof(Buffer); lRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey,0,KEY_ALL_ACCESS,&hResult); if(lRet!=ERROR_SUCCESS) { returnFALSE; } lRet=RegQueryValueEx(hResul
6、t,_T("ACUserIdle"),NULL,NULL,(LPBYTE)Buffer,&size); if(lRet!=ERROR_SUCCESS) { returnFALSE; } RegCloseKey(hResult); returnTRUE;}DWORDGetPowerOffTime(){ DWORDACUserIdleTimeout; if(GetAutoPowerOffTime((byte*)&ACUserIdleTimeout)) { if(ACUse
7、rIdleTimeout==0) { ACUserIdleTimeout=INFINITE; } else { if(ACUserIdleTimeout>MAXACTIVITYTIMEOUT) { ACUserIdleTimeout=MAXACTIVITYTIMEOUT; } } //转成毫秒 if(ACUserIdleTimeout!=INFIN
8、ITE) { ACUserIdleTimeout*=1000; } } else { ACUserIdleTimeout=INFINITE; } returnACUserIdleTimeout;}DWORDEventThread(PVOIDpArg){ DWORD dwResult; DWORD dwTimeout=INFINITE; HANDLEgEvent[2]; //创建事件 gEvent[0]=CreateEvent(NU
9、LL,FALSE,FALSE,L"PowerOffTimeOutChange"); gEvent[1]=CreateEvent(NULL,FALSE,FALSE,L"UserInputEvent"); //读自动关机时间 dwTimeout=GetPowerOffTime(); while(1) { dwResult=WaitForMultipleObjects(2,gEvent,FALSE,dwTimeout); if(dwResult==WAIT_TIMEOUT) {
10、 ExitWince(); } else { if(dwResult==WAIT_OBJECT_0) {