我正在尝试获得系统经过的时间。我试图读取或写入受保护的内存。这通常表明此行中其他内存损坏(信息:它为lcreationtime,lexittime,lkernaltime和lusertime获取值0)
Declare Function GetProcessTimes Lib "kernel32" (ByVal hProcess As Long, ByRef lpCreationTime As Long, ByRef lpExitTime As Long, ByRef lpKernelTime As Long, ByRef lpUserTime As Long) As Long
Private Declare Function GetSystemTimeAsFileTime Lib "kernel32" (ByRef lpFileTime As Long) As Long
.NET API:
Private Structure Cur64Math
Dim Value As Long
End Structure
Private Structure Cur64Diff
Dim cLastValue As Cur64Math
Dim cLastDiff As Cur64Math
End Structure
我在下面的Structures中创建了将值转换为Long。
Friend Function CPUElapsedTimes() As String
Dim CreationTime, ExitTime As FILETIME
Dim UserTime, KernelTime As FILETIME
Dim CurrentTime As FILETIME
Dim lcreationtime As Cur64Math
Dim lexittime As Cur64Math
Dim lusertime As Cur64Math
Dim lkerneltime As Cur64Math
Dim lcurrenttime As Cur64Math
Dim lProcessID As Integer
lProcessID = GetCurrentProcess
GetSystemTimeAsFileTime(lcurrenttime.Value)
If GetProcessTimes(lProcessID, lcreationtime.Value, lexittime.Value, lkerneltime.Value, lusertime.Value) Then
.cLastDiff.Value = lcurrenttime.Value - .cLastValue.Value
.cLastValue.Value = lcurrenttime.Value
GetElapsedTimes = mFmtDiff(mUserTime.cLastDiff)
'Here using Private mUserTime As Cur64Diff
End If
Exit Function
然后返回给出差异的字符串的函数如下:
.bat