VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "xtimer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function QueryPerformanceCounter Lib "kernel32" _
       (lpPerformanceCount As LARGE_INTEGER) As Long
                    
Private Declare Function QueryPerformanceFrequency Lib "kernel32" _
        (lpFrequency As LARGE_INTEGER) As Long

Private Type LARGE_INTEGER
  Lo As Long
  Hi As Long
End Type

Dim Strt As LARGE_INTEGER
Dim Ende As LARGE_INTEGER
Dim Freq As LARGE_INTEGER
Dim Calibr As Double

Private Sub Class_Initialize()
  Call QueryPerformanceFrequency(Freq)
End Sub

Public Sub Calibrieren()
  Call QueryPerformanceCounter(Strt)
  Call QueryPerformanceCounter(Ende)
  Calibr = (D(Ende) - D(Strt)) / D(Freq) * 1000 'ms
End Sub

Public Sub start()
  Call QueryPerformanceCounter(Strt)
End Sub

Public Sub Halt()
  Call QueryPerformanceCounter(Ende)
End Sub

Public Property Get RunTime() As Variant  'ms
  RunTime = (D(Ende) - D(Strt)) / D(Freq) * 1000 - Calibr
End Property

Private Function D(x As LARGE_INTEGER) As Double
  Dim l As Double, h As Double
    l = x.Lo
    h = x.Hi
    If l < 0 Then l = 4294967296# + l + 1
    If h < 0 Then h = 4294967296# + h + 1
    D = l + h * 4294967296#
End Function
'-------------------- Ende Code xTimer  ---------------------


