-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmdGlobals.bas
73 lines (65 loc) · 2.75 KB
/
mdGlobals.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Attribute VB_Name = "mdGlobals"
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function IsBadReadPtr Lib "kernel32" (ByVal lp As Long, ByVal ucb As Long) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Public DebugForm As Form1
Public ChatWindows As Collection
Public Function DesignDumpArray(baData() As Byte, Optional ByVal Pos As Long, Optional ByVal Size As Long = -1) As String
If Size < 0 Then
Size = UBound(baData) + 1 - Pos
End If
If Size > 0 Then
DesignDumpArray = DesignDumpMemory(VarPtr(baData(Pos)), Size)
End If
End Function
Public Function DesignDumpMemory(ByVal lPtr As Long, ByVal lSize As Long) As String
Dim lIdx As Long
Dim sHex As String
Dim sChar As String
Dim lValue As Long
Dim aResult() As String
ReDim aResult(0 To (lSize + 15) \ 16) As String
For lIdx = 0 To ((lSize + 15) \ 16) * 16
If lIdx < lSize Then
If IsBadReadPtr(lPtr, 1) = 0 Then
Call CopyMemory(lValue, ByVal lPtr, 1)
sHex = sHex & Right$("0" & Hex$(lValue), 2) & " "
If lValue >= 32 Then
sChar = sChar & Chr$(lValue)
Else
sChar = sChar & "."
End If
Else
sHex = sHex & "?? "
sChar = sChar & "."
End If
Else
sHex = sHex & " "
End If
If ((lIdx + 1) Mod 4) = 0 Then
sHex = sHex & " "
End If
If ((lIdx + 1) Mod 16) = 0 Then
aResult(lIdx \ 16) = Right$("000" & Hex$(lIdx - 15), 4) & " - " & sHex & sChar
sHex = vbNullString
sChar = vbNullString
End If
lPtr = (lPtr Xor &H80000000) + 1 Xor &H80000000
Next
DesignDumpMemory = Join(aResult, vbCrLf)
End Function
Public Property Get TimerEx() As Double
Dim cFreq As Currency
Dim cValue As Currency
Call QueryPerformanceFrequency(cFreq)
Call QueryPerformanceCounter(cValue)
TimerEx = cValue / cFreq
End Property
Public Sub DebugLog(sModule As String, sFunction As String, sText As String, Optional ByVal eType As LogEventTypeConstants = vbLogEventTypeInformation)
Debug.Print Format$(TimerEx, "0.000") & " " & Switch( _
eType = vbLogEventTypeError, "[ERROR]", _
eType = vbLogEventTypeWarning, "[WARN]", _
True, "[INFO]") & " " & sText & " [" & sModule & "." & sFunction & "]"
End Sub