PDA

Click to See Complete Forum and Search --> : How to use the following APIs


007shahid
Feb 22nd, 2002, 03:17 AM
Public Declare Function QueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As LARGE_INTEGER) As Long

Public Declare Function QueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As LARGE_INTEGER) As Long

Si_the_geek
Feb 22nd, 2002, 04:02 AM
go to http://www.allapi.net, and either look at their examples, or download the API-Guide which had definitions and examples for most API calls ;)

MerrionComputin
Feb 22nd, 2002, 04:18 AM
Declarations (as per yopur post)

Private Type LARGE_INTEGER
HiInt As Long
LoInt As Long
End Type

Private Declare Function QueryPerformanceFrequency Lib "kernel32.dll" (lpFrequency As LARGE_INTEGER) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32.dll" (lpFrequency As LARGE_INTEGER) As Long

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)



Use (as per ApiSystem.PerformanceCounter)

Public Property Get PerformanceCounter() As Currency

Dim lret As Long
Dim lCounter As LARGE_INTEGER

lret = QueryPerformanceCounter(lCounter)
If Err.LastDllError <> 0 Then
ReportError Err.LastDllError, "ApiSystem:PerformanceCounter", GetLastSystemError
Else
PerformanceCounter = LargeIntToCurrency(lCounter)
End If

End Property

Public Property Get PerformanceFrequency() As Currency

Dim lret As Long
Dim lFrequency As LARGE_INTEGER

lret = QueryPerformanceFrequency(lFrequency)
If Err.LastDllError <> 0 Then
ReportError Err.LastDllError, "ApiSystem:PerformanceFrequency", GetLastSystemError
Else
PerformanceFrequency = LargeIntToCurrency(lFrequency)
End If

End Property


Utility function to convert LARGE_INTEGER...

Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
'copy 8 bytes from the large integer to an ampty currency
CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
'adjust it
LargeIntToCurrency = LargeIntToCurrency * 10000
End Function


HTH,
Duncan