首页
社区
课程
招聘
[求助]编写驱动挂钩时钟中断
发表于: 2008-4-6 09:07 4822

[求助]编写驱动挂钩时钟中断

2008-4-6 09:07
4822
我想在XP下得到精确的系统时间,但是用SetTimer之类的函数得到的时间误差都比较大,我想通过驱动挂钩系统时钟中断或许可以得到精确的系统时间,小弟初学驱动开发,那位能提供一些例程或者是方法,小弟感激不尽!

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 1852
活跃值: (504)
能力值: (RANK:1010 )
在线值:
发帖
回帖
粉丝
2
如果需要取得精确的系统时间,使用QueryPerformanceFrequency和QueryPerformanceCounter

如果需要精确定时例如1ms,使用等待定时器的APC机制( CreateWaitableTime/SetWaitableTime)
2008-4-7 09:22
0
雪    币: 231
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
谢谢老大指点,我试了APC机制,但是在定时20ms间隔时他的误差会在一两毫秒间,我需要的最好能在1ms内,不知是不是程序的问题,请老大指正一下。
CreateWaitableTime/SetWaitableTime
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>

#define _SECOND 10000000

typedef struct _MYDATA {
   TCHAR *szText;
   DWORD dwValue;
} MYDATA;

VOID CALLBACK TimerAPCProc(
   LPVOID lpArg,               // Data value
   DWORD dwTimerLowValue,      // Timer low value
   DWORD dwTimerHighValue )    // Timer high value

{
   MYDATA *pMyData = (MYDATA *)lpArg;
   SYSTEMTIME st;
   GetLocalTime(&st);
   printf( "Message: %s\nValue: %d\n\n", pMyData->szText,
          pMyData->dwValue );
   printf("st.wSecond=%d,st.wMilliseconds=%d\n",st.wSecond,st.wMilliseconds);
   MessageBeep(0);

}

void main( void )
{
   HANDLE          hTimer;
   BOOL            bSuccess;
   __int64         qwDueTime;
   LARGE_INTEGER   liDueTime;
   MYDATA          MyData;
   TCHAR           szError[255];

   MyData.szText = "This is my data.";
   MyData.dwValue = 100;

   if ( hTimer = CreateWaitableTimer(
           NULL,                   // Default security attributes
           FALSE,                  // Create auto-reset timer
           "MyTimer" ) )           // Name of waitable timer
   {
      __try
      {
            qwDueTime = -2 * _SECOND;

          liDueTime.LowPart  = (DWORD) ( qwDueTime & 0xFFFFFFFF );
         liDueTime.HighPart = (LONG)  ( qwDueTime >> 32 );

         bSuccess = SetWaitableTimer(
            hTimer,           // Handle to the timer object
            &liDueTime,       // When timer will become signaled
            10,             // Periodic timer interval of 2 seconds
            TimerAPCProc,     // Completion routine
            &MyData,          // Argument to the completion routine
            FALSE );          // Do not restore a suspended system

         if ( bSuccess )
         {
            for ( ; MyData.dwValue < 1000; MyData.dwValue += 100 )
            {
               SleepEx(
                  INFINITE,     // Wait forever
                  TRUE );       // Put thread in an alertable state
            }

         }
         else
         {
            wsprintf( szError, "SetWaitableTimer failed with Error \
               %d.", GetLastError() );
            MessageBox( NULL, szError, "Error", MB_ICONEXCLAMATION );
         }

      }
      __finally
      {
         CloseHandle( hTimer );
      }
   }
   else
   {
      wsprintf( szError, "CreateWaitableTimer failed with Error %d.",
          GetLastError() );
      MessageBox( NULL, szError, "Error", MB_ICONEXCLAMATION );
   }
}
2008-4-7 22:38
0
雪    币: 231
活跃值: (12)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
请教一下老大们,在WINXP下是否还可以得到原来的INT8时钟中断,APIC里面的好像没有了,哪位老大能指导一下.
2008-4-20 22:09
0
游客
登录 | 注册 方可回帖
返回
//