阅读:1744回复:4
关于如何在驱动程序中获得当前的时间
我的驱动程序要想获得当前的系统时间,我用time函数编辑出错,我也把time.h包进去了,不行。请问有什么别的方法吗?急!谢谢!
|
|
|
沙发#
发布于:2001-09-05 21:23
我在软件驱动精华区中有篇文章,你可以参考一下。
|
|
|
板凳#
发布于:2001-09-06 09:16
谢谢LitteSW大虾的回复,但我写的是WDM驱动,我是用kerneldriver
作为工具的,你的代码中的VTD_get_data_time()还行吗? 我可不可以直接调用sdk的函数呢,如:getsystemtime()?若不行的话,你还是给我指条明路吧。急!鞠躬! |
|
|
地板#
发布于:2001-09-06 12:43
我以前也做过WDM下的。
我找一下,晚一点贴上来。 |
|
|
地下室#
发布于:2001-09-06 20:18
我做了个类。在调用时:
TIME_ITEM strData; CTime MyTime; MyTime.GetDate(&strData); 其中类定义和结构定义如下: #ifndef __TIME_ITEM__ #define __TIME_ITEM__ typedef struct { // 日期信息 ULONG dwYears; ULONG dwMonths; ULONG dwThisDays; // 时间信息 ULONG dwHours; ULONG dwMinutes; ULONG dwSeconds; ULONG dwMSeconds; } TIME_ITEM, *PTIME_ITEM; #endif class CTime { public: CTime(); virtual ~CTime(); public: void GetDate(PTIME_ITEM pDate); void CaculateDate(LARGE_INTEGER dwDays); public: ULONG Days() { return m_dwDays; } LARGE_INTEGER GetLGTime() { return m_lgiTime; } ULONG MilliSeconds() { return m_dwMilliSeconds; } ULONG Seconds() { return m_dwSeconds; } ULONG Minutes() { return m_dwMinutes; } ULONG Hours() { return m_dwHours; } ULONG Years() { return m_dwYears; } ULONG Months() { return m_dwMonths; } ULONG ThisDays() { return m_dwThisDays; } void SetDays(ULONG dw) { m_dwDays = dw; } void SetLGTime(LARGE_INTEGER dw){ m_lgiTime = dw; } void SetMilliSeconds(ULONG dw) { m_dwMilliSeconds = dw; } void SetSeconds(ULONG dw) { m_dwSeconds = dw; } void SetMinutes(ULONG dw) { m_dwMinutes = dw; } void SetHours(ULONG dw) { m_dwHours = dw; } void SetYears(ULONG dw) { m_dwYears = dw; } void SetMonths(ULONG dw) { m_dwMonths = dw; } void SetThisDays(ULONG dw) { m_dwThisDays = dw; } public: LARGE_INTEGER m_lgiTime; // since midnight ULONG m_dwDays; // since jan,1,1601 ULONG m_dwMilliSeconds; ULONG m_dwSeconds; ULONG m_dwMinutes; ULONG m_dwHours; ULONG m_dwYears; ULONG m_dwMonths; ULONG m_dwThisDays; }; Time.cpp文件如下: #include "Time.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ///////////////////////////////////////////////////////////////////////////// // CTime class member functions CTime::CTime() { // set milliseconds since midnight LARGE_INTEGER lgiTime; KeQuerySystemTime(&lgiTime); SetLGTime(lgiTime); } // End of CTime::CTime() CTime::~CTime() { } // End of CTime::~CTime() void CTime::GetDate(PTIME_ITEM pDate) { // get year/month/day CaculateDate(GetLGTime()); // fill PDATE_ITEM struct pDate->dwYears = Years(); pDate->dwMonths = Months(); pDate->dwThisDays = ThisDays(); pDate->dwHours = Hours(); pDate->dwMinutes = Minutes(); pDate->dwSeconds = Seconds(); pDate->dwMSeconds = MilliSeconds(); } // End of CTime::GetDate() void CTime::CaculateDate(LARGE_INTEGER lgiTime) { int iMonDay[2][13] = { {0,31,59,90,120,151,181,212,243,273,304,334,365}, {0,31,60,91,121,152,182,213,244,274,305,335,366}}; int iDays, iYear, iMonth; int iHours, iMinutes, iSeconds, iMSeconds; int iLeapYear = 0; // from 1601.1.1 for ( iYear = 1601; ; ) { if ( ( iYear % 400 == 0) || ( iYear % 100 != 0) && ( iYear % 4 == 0 ) ) iLeapYear = 1; if ( lgiTime.QuadPart <= (365 + iLeapYear) * 864000000000) break; lgiTime.QuadPart -= (365 + iLeapYear) * 864000000000; iYear++; iLeapYear = 0; } SetYears(ULONG(iYear)); for ( iMonth = 0; ; iMonth++ ){ if ( (iMonDay[iLeapYear][iMonth] * 864000000000) >= lgiTime.QuadPart ){ lgiTime.QuadPart -= iMonDay[iLeapYear][iMonth-1] * 864000000000; break; } } SetMonths(ULONG(iMonth)); iDays = (ULONG)(lgiTime.QuadPart / 864000000000 + 1); // SetThisDays(ULONG(iDays)); lgiTime.QuadPart = lgiTime.QuadPart % 864000000000; iHours = (ULONG)(lgiTime.QuadPart / 36000000000); if (iHours > 15) { iDays += 1; SetThisDays(ULONG(iDays)); iHours -= 16; SetHours(ULONG(iHours)); } else { SetThisDays(ULONG(iDays)); iHours += 8; SetHours(ULONG(iHours)); } lgiTime.QuadPart = lgiTime.QuadPart % 36000000000; iMinutes = (ULONG)(lgiTime.QuadPart / 600000000); SetMinutes(ULONG(iMinutes)); lgiTime.QuadPart = lgiTime.QuadPart % 600000000; iSeconds = (ULONG)(lgiTime.QuadPart/ 10000000); SetSeconds((ULONG)iSeconds); lgiTime.QuadPart = lgiTime.QuadPart % 10000000; iMSeconds = (ULONG)(lgiTime.QuadPart/ 100000); SetMilliSeconds((ULONG)iMSeconds); } // End of CTime::CaculateDate() BTW:源码复上,别忘了给分。 哈哈!!! 今天下午没事,又看了一遍,发现有错,不好意思,已改正。 [LitteSW 编辑于 2001-09-07 21:37] |
|
|