Attribute VB_Name = "RegEdit"
'REG_NONE=0
'REG_SZ=1
'REG_EXPAND_SZ=2
'REG_BINARY=3
'REG_DWORD=4
'REG_DWORD_LITTLE_ENDIAN=4
'REG_DWORD_BIG_ENDIAN=5
'REG_LINK=6
'REG_MULTI_SZ=7
'REG_RESOURCE_LIST=8
'REG_FULL_RESOURCE_DESCRIPTOR=9
'REG_RESOURCE_REQUIREMENTS_LIST=10
'REG_QWORD=11
'REG_QWORD_LITTLE_ENDIAN=11

Public Enum T_KeyClasses
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
End Enum
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const ERROR_SUCCESS = 0&
Public RegKeys1, RegKeys11, RegKeys12 As String
Public RegKeys2 As String
Public RegKeys3 As String
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKey As Long) As Long

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
(ByVal HKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
(ByVal HKey As Long, ByVal lpSubKey As String) As Long

Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
(ByVal HKey As Long, ByVal lpValueName As String) As Long

Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
(ByVal HKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal HKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
lpType As Long, lpData As Any, lpcbData As Long) As Long

Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal HKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, lpData As Any, ByVal cbData As Long) As Long

Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
(ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName _
As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, _
lpftLastWriteTime As Any) As Long

Public Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" _
(ByVal HKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As _
Byte, lpcbData As Long) As Long

Function GetKeys(ByVal H_Key As Long, ByVal HSubDir As String)
    Dim HKey As Long, Counter As Long, sSave As String
 
    RegOpenKey H_Key, HSubDir, HKey
    Do
        sSave = String(255, 0)
        If RegEnumKeyEx(HKey, Counter, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
        RegKeys1 = RegKeys1 & StripTerminator(sSave) & "@@@"
        Counter = Counter + 1
    Loop
    RegCloseKey HKey
End Function

Public Sub CreateKey(HKey As Long, strPath As String)
    Dim keyhand&
    RegCreateKey HKey, strPath, keyhand&
    RegCloseKey keyhand&
End Sub

Public Sub DeleteKey(HKey As Long, ByVal strPath As String)
    RegDeleteKey HKey, strPath
End Sub

Function GetValues(ByVal H_Key As String, ByVal HSubKey As String)
 Dim HKey As Long, Counter As Long, sSave As String
  RegOpenKey H_Key, HSubKey, HKey
  Counter = 0
  Do
     sSave = String(255, 0)
     If RegEnumValue(HKey, Counter, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
     getS = StripTerminator(sSave)
     If getS = "" Then getS = "(default)"
     RegKeys2 = RegKeys2 & getS & "@@@"
     Counter = Counter + 1
  Loop
  RegCloseKey HKey
End Function

Public Sub DeleteSettingString(ByVal HKey As Long, _
ByVal strPath As String, ByVal strValue As String)
Dim hCurKey As Long
Dim lRegResult As Long

lRegResult = RegOpenKey(HKey, strPath, hCurKey)

lRegResult = RegDeleteValue(hCurKey, strValue)

lRegResult = RegCloseKey(hCurKey)

End Sub

Public Sub SaveSettingString(HKey As Long, ByVal strPath As String, ByVal strValue As String, ByVal strdata As String)
    Dim keyhand&
    RegCreateKey HKey, strPath, keyhand&
    RegSetValueEx keyhand&, strValue, 0, 1, ByVal strdata, Len(strdata)
    RegCloseKey keyhand&
End Sub

Public Function GetSettingString(ByVal HKey As Long, _
ByVal strPath As String, ByVal strValue As String, Optional _
Default As String) As String
Dim hCurKey As Long
Dim lResult As Long
Dim lValueType As Long
Dim strBuffer As String
Dim lDataBufferSize As Long
Dim intZeroPos As Integer
Dim lRegResult As Long
Dim strtype As String
If Not IsEmpty(Default) Then
GetSettingString = Default
Else
GetSettingString = ""
End If

lRegResult = RegOpenKey(HKey, strPath, hCurKey)
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _
lValueType, ByVal 0&, lDataBufferSize)

If lRegResult = ERROR_SUCCESS Then

If lValueType = REG_SZ Then
strtype = "REG_SZ"
End If
If lValueType = REG_BINARY Then
strtype = "REG_BINARY"
End If
If lValueType = REG_DWORD Then
strtype = "REG_DWORD"
End If
If lValueType = REG_EXPAND_SZ Then
strtype = "REG_EXPAND_SZ"
End If


ee = String(lValueType, " ")
strBuffer = String(lDataBufferSize, " ")
lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, _
ByVal strBuffer, lDataBufferSize)

intZeroPos = InStr(strBuffer, Chr$(0))
If intZeroPos > 0 Then
GetSettingString = strtype & "****" & Left$(strBuffer, intZeroPos - 1)
Else
GetSettingString = strtype & "****" & strBuffer
End If

'End If

'Else
End If

lRegResult = RegCloseKey(hCurKey)
End Function

Private Function StripTerminator(sInput As String) As String
    Dim ZeroPos As Integer
    ZeroPos = InStr(1, sInput, vbNullChar)
    If ZeroPos > 0 Then
        StripTerminator = Left$(sInput, ZeroPos - 1)
    Else
        StripTerminator = sInput
    End If
End Function


