Option Explicit
Private Declare Function GetProcessTimes Lib "kernel32" (ByVal hProcess As Long, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
' Sneaky type that will allow us to neatly convert the double words into a nicely scaled currency value
' representing milliseconds
Private Type DWORDPROXIE
Value As Currency
End Type
Private Type ProcessTimes
CreationTime As SYSTEMTIME ' Time process started
ExitTime As SYSTEMTIME ' Generally not useful
KernelTime As Currency ' elapsed time in milliseconds
UserTime As Currency ' elapsed time in milliseconds
End Type
Private Function vbGetProcessTimes(hProcess As Long) As ProcessTimes
Dim CreationTime As FILETIME
Dim ExitTime As FILETIME
Dim KernelTime As FILETIME
Dim UserTime As FILETIME
Dim result As Long
Dim UsableTime As SYSTEMTIME
Dim TempTime As DWORDPROXIE
GetProcessTimes hProcess, CreationTime, ExitTime, KernelTime, UserTime
' Some time conversions
FileTimeToLocalFileTime CreationTime, CreationTime
FileTimeToLocalFileTime ExitTime, ExitTime ' Don't really care about this one generally
FileTimeToSystemTime CreationTime, vbGetProcessTimes.CreationTime
FileTimeToSystemTime ExitTime, vbGetProcessTimes.ExitTime
LSet TempTime = KernelTime
vbGetProcessTimes.KernelTime = TempTime.Value
LSet TempTime = UserTime
vbGetProcessTimes.UserTime = TempTime.Value
End Function