谁可以为我调试这个代码关于win ce中的看门狗定时器?

时间:2014-10-16 12:04:12

标签: windows-ce

#include <windows.h>
#include <pkfuncs.h>
#define WATCHDOG_NAME L"wd_critproc"
#define WATCHDOG_PERIOD 5000 // milliseconds
#define WATCHDOG_WAIT_TIME 2000 // milliseconds
//WDOG_NO_DFLT_ACTION, WDOG_KILL_PROCESS, WDOG_RESET_DEVICE
#define WATCHDOG_DEFAULT_ACTION WDOG_RESET_DEVICE 
#define MAX_COUNT 10
int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{
 HANDLE hWatchDogTimer=NULL;
 LPCWSTR pszWatchDogName=WATCHDOG_NAME;
 DWORD dwPeriod=WATCHDOG_PERIOD;
 DWORD dwWait=WATCHDOG_WAIT_TIME;
 DWORD dwDefaultAction=WATCHDOG_DEFAULT_ACTION;
 DWORD dwCount=0;
 BOOL bRet=FALSE;

    wprintf((TEXT("[critproc] Critical process start\r\n")));
   wprintf((TEXT("[critproc] Calling CreateWatchDogTimer...\r\n")));
//createwatchdogtimer api is being called here
 hWatchDogTimer = 
CreateWatchDogTimer(pszWatchDogName, dwPeriod,dwWait, dwDefaultAction,0,0);
 if (! hWatchDogTimer)
 {
  wprintf((TEXT("[critproc] Invalid NULL handle, leaving app\r\n")));
  return 1;
 }
//checking if the error already exists then same watchdog timer is not called
 if (GetLastError()==ERROR_ALREADY_EXISTS)
 {
   wprintf((TEXT("[critproc] WatchDog with this name already exists,
   leaving app\r\n")));
   return 1;
 }
    wprintf((TEXT("[critproc] Valid handle returned [0x%08x]\r\n")),
        hWatchDogTimer);
 wprintf((TEXT("[critproc] Starting watchdog timer...\r\n")));
 bRet = StartWatchDogTimer(hWatchDogTimer,0);
 if (! bRet)
 {
        wprintf((TEXT("[critproc] StartWatchDogTimer failed,
   GetLastError returned 0x%x\r\n")),GetLastError());
  CloseHandle(hWatchDogTimer);
  return 1;
 }
 wprintf((TEXT("[critproc] Watchdog timer started successfully\r\n")));
    dwCount=0;
 while ((dwCount++)<MAX_COUNT)
 {
  BOOL bRetVal=0;
     wprintf((TEXT("[critproc] Refreshing watchdog timer... [%d]\r\n")),dwCount);
     bRetVal = RefreshWatchDogTimer(hWatchDogTimer,0);
  if (!bRetVal)
  {
   wprintf((TEXT("[critproc] Failed to refresh watchdog timer,
    GetLastError returned 0x%x\r\n")),GetLastError());
   CloseHandle(hWatchDogTimer);
   return 1;
  }

  Sleep(1000);
 }

    wprintf((TEXT("[critproc] Stopping watchdog timer refresh\r\n")));
    dwCount=0;
 while (++dwCount)
 {
        wprintf((TEXT("[critproc] The watchdog should timeout in  \
   a few seconds... [%d]\r\n")),dwCount);
  Sleep(1000);
 }
 wprintf((TEXT("[critproc] Leaving app (should never be here)\r\n")));
 CloseHandle(hWatchDogTimer);
    return 0;
}

2 个答案:

答案 0 :(得分:0)

  

我得到的错误是关于wmain函数说本地函数定义是非法的 -

您不是要求调试,而是要求修复编译错误!

    Sleep(1000);
} 
^~~~~~~ this is what compiler is complaining about          

答案 1 :(得分:0)

尝试正确定义main:

int _tmain(int argc, TCHAR* argv[])