home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / EASYREG.ZIP / EasyRegistry.Cls next >
Encoding:
Visual Basic class definition  |  1998-01-16  |  24.6 KB  |  695 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsEasyRegistry"
  6. Attribute VB_GlobalNameSpace = True
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11. '
  12. ' ___________________________________________________
  13. '  Luca Minudel                    software designer
  14. '  Italy Conegliano(TV)
  15. '  voice & fax                     +39 (0)438 412280
  16. '  e-mail                      luca.minudel@nline.it
  17. '  WWW                       (italian language used)
  18. '  http://www.geocities.com/SiliconValley/Vista/4041
  19. '
  20. ' If you discover any bug or improvements to EasyRegistry please tell me,
  21. ' that 's why I'm sharing my work.
  22. ' I 'll correct any bug as soon as possible.
  23. ' Suggestions are welcome.
  24. '
  25. '
  26. ' -- Current Key
  27. Private strCurrentDirectory As String
  28. Private lngKeyHandle As Long
  29. '
  30. ' --- Constants
  31. '
  32. '
  33. ' --- DirValue return a variant that is NULL or is an array(0 to 2).
  34. '     These are index constants with respective meaning.
  35. '
  36. Public Enum enmDirValueIndex
  37.   erValueName
  38.   erValue
  39.   erValueType
  40. End Enum
  41. '
  42. ' --- ValueOf and DirValue receive and return data types of data they are
  43. '     managing. These are valid data type constants.
  44. '
  45. Public Enum enmDataType
  46.  erSTRING
  47.  erByte
  48.  erDWord
  49. End Enum
  50. '
  51. ' --- ValueOf return an array with many rappresentations for each value.
  52. '     These are index constants with respective meaning.
  53. '
  54. Public Enum enmValueOfIndex
  55.   erStringFormat
  56.   erByteFormat
  57.   erDWordFormat
  58. End Enum
  59. '
  60. ' ------------------------------- API DEL REGISTRO -------------------------
  61. '
  62. Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
  63.         (ByVal hKey As Long, ByVal lpSubKey As String, _
  64.          ByVal ulOptions As Long, ByVal samDesired As Long, _
  65.          phkResult As Long) As Long
  66. Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
  67. Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" _
  68.         (ByVal hKey As Long, ByVal lpClass As String, _
  69.          lpcbClass As Long, lpReserved As Long, lpcSubKeys As Long, _
  70.          lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, _
  71.          lpcValues As Long, lpcbMaxValueNameLen As Long, _
  72.          lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, _
  73.          lpftLastWriteTime As Any) As Long
  74. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
  75.         (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
  76.          lpcbName As Long, lpReserved As Long, ByVal lpClass As String, _
  77.          lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
  78. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" _
  79.         (ByVal hKey As Long, ByVal dwIndex As Long, _
  80.          ByVal lpValueName As String, lpcbValueName As Long, _
  81.          lpReserved As Long, lpType As Long, lpData As Any, _
  82.          lpcbData As Long) As Long
  83. Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" _
  84.         (ByVal hKey As Long, ByVal lpValueName As String, _
  85.          ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, _
  86.          lpcbData As Long) As Long
  87. Private Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" _
  88.         (ByVal hKey As Long, ByVal lpValueName As String, _
  89.          ByVal Reserved As Long, ByVal dwType As Long, _
  90.          ByVal lpData As String, ByVal cbData As Long) As Long
  91. Private Declare Function RegDeleteKey Lib "advapi32" Alias "RegDeleteKeyA" _
  92.         (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  93. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
  94.         (ByVal hKey As Long, ByVal lpValueName As String) As Long
  95. Private Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" _
  96.         (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, _
  97.          ByVal lpClass As String, ByVal dwOptions As Long, _
  98.          ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, _
  99.          phkResult As Long, lpdwDisposition As Long) As Long
  100.  
  101. '
  102. ' ---------------------------- COSTANTI DEL REGISTRO -----------------------
  103. '
  104. ' -- HANDLE DELLE CHIAVI PREDEFINITE
  105. Const HKEY_CLASSES_ROOT = &H80000000
  106. Const HKEY_CURRENT_USER = &H80000001
  107. Const HKEY_LOCAL_MACHINE = &H80000002
  108. Const HKEY_USERS = &H80000003
  109. Const HKEY_PERFORMANCE_DATA = &H80000004
  110. Const HKEY_CURRENT_CONFIG = &H80000005
  111. Const HKEY_DYN_DATA = &H80000006
  112. ' -- SICUREZZA
  113. Const READ_CONTROL = &H20000
  114. Const SYNCHRONIZE = &H100000
  115. Const STANDARD_RIGHTS_ALL = &H1F0000
  116. Const STANDARD_RIGHTS_READ = READ_CONTROL
  117. Const STANDARD_RIGHTS_WRITE = READ_CONTROL
  118. Const KEY_QUERY_VALUE = &H1
  119. Const KEY_SET_VALUE = &H2
  120. Const KEY_CREATE_SUB_KEY = &H4
  121. Const KEY_ENUMERATE_SUB_KEYS = &H8
  122. Const KEY_NOTIFY = &H10
  123. Const KEY_CREATE_LINK = &H20
  124. Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  125. Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  126. Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
  127. Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  128. ' -- CODICI DI ERRORE RITORNATI DALLE API DI REGISTRO
  129. Const ERROR_SUCCESS = 0&
  130. Const ERROR_FILE_NOT_FOUND = 2&
  131. Const ERROR_BADDB = 1009&
  132. Const ERROR_BADKEY = 1010&
  133. Const ERROR_CANTOPEN = 1011&
  134. Const ERROR_CANTREAD = 1012&
  135. Const ERROR_CANTWRITE = 1013&
  136. Const ERROR_OUTOFMEMORY = 14&
  137. Const ERROR_INVALID_PARAMETER = 87&
  138. Const ERROR_ACCESS_DENIED = 5&
  139. ' -- TIPI DI DATO
  140. Const REG_NONE = 0
  141. Const REG_SZ = 1
  142. Const REG_EXPAND_SZ = 2
  143. Const REG_BINARY = 3
  144. Const REG_DWORD = 4
  145. Const REG_DWORD_LITTLE_ENDIAN = 4
  146. Const REG_DWORD_BIG_ENDIAN = 5
  147. Const REG_LINK = 6
  148. Const REG_MULTI_SZ = 7
  149. Const REG_RESOURCE_LIST = 8
  150. Const REG_FULL_RESOURCE_DESCRIPTOR = 9
  151. Const REG_RESOURCE_REQUIREMENTS_LIST = 10
  152. ' -- OPZIONI
  153. Const REG_OPTION_NON_VOLATILE = 0&
  154. Const REG_OPTION_VOLATILE = &H1
  155. '
  156. ' --------------------------- TIPI DI DATO API REGISTRO --------------------
  157. '
  158. Private Type SECURITY_ATTRIBUTES
  159.   nLength As Long
  160.   lpSecurityDescriptor As Long
  161.   bInheritHandle As Long
  162. End Type
  163. Private Type FILETIME
  164.   dwLowDateTime As Long
  165.   dwHighDateTime As Long
  166. End Type
  167. Private Sub Class_Initialize()
  168.   strCurrentDirectory = ""
  169.   lngKeyHandle = 0
  170. End Sub
  171. Private Sub Class_Terminate()
  172.   ' cHIUDI TUTTE LE CHIAVI
  173.   If strCurrentDirectory <> "" Then TestAPIError RegCloseKey(lngKeyHandle)
  174. End Sub
  175. '
  176. ' --------------------------- METODI/PROPRIETA' PUBBLICHE ------------------
  177. '
  178. Property Get CurrentKey() As String
  179.   CurrentKey = strCurrentDirectory
  180. End Property
  181. Public Sub Cd(ByVal strDirectory As String)
  182. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 04/05/97 2.17.16
  183.   On Error GoTo Cd_Err
  184.   CdExt strDirectory, KEY_ALL_ACCESS
  185.   Exit Sub
  186.  
  187. Cd_Err:
  188.   Err.Raise Err.Number, Err.Source, Err.Description
  189. End Sub
  190.  
  191. Public Function DirKey() As Variant
  192. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 04/05/97 2.17.16
  193. Dim lngSubKeysCount As Long
  194. Dim lngKeyLenght As Long
  195. Dim strKeyName As String
  196. Dim lngI As Long
  197. Dim astrKey() As String
  198. Dim lngMaxSubKeyLen As Long
  199. Dim lngMaxClassLen As Long
  200. Dim lngValues As Long
  201. Dim udtData As FILETIME
  202. Dim lngMaxValueNameLen As Long
  203. Dim lngMaxValueLen As Long
  204. Dim lngSecurityDescriptor As Long
  205. Dim strClass As String
  206. Dim lngClass As Long
  207.   On Error GoTo DirKey_Err
  208.   If CurrentKey = "" Then
  209.     ReDim astrKey(0 To 5) As String
  210.     astrKey(0) = "HKEY_CLASSES_ROOT"
  211.     astrKey(1) = "HKEY_CURRENT_USER"
  212.     astrKey(2) = "HKEY_LOCAL_MACHINE"
  213.     astrKey(3) = "HKEY_USERS"
  214.     astrKey(4) = "HKEY_DYN_DATA"
  215.     astrKey(5) = "HKEY_CURRENT_CONFIG"
  216. DirKey = astrKey
  217.   Else
  218.     CdExt CurrentKey, KEY_READ
  219.     udtData.dwHighDateTime = 0
  220.     udtData.dwLowDateTime = 0
  221.     lngKeyLenght = 1024
  222.     strKeyName = String$(1024, 32)
  223.     TestAPIError RegQueryInfoKey(lngKeyHandle, _
  224.                                  strKeyName, lngKeyLenght, ByVal 0&, _
  225.                                  lngSubKeysCount, _
  226.                                  lngMaxSubKeyLen, lngMaxClassLen, _
  227.                                  lngValues, lngMaxValueNameLen, _
  228.                                  lngMaxValueLen, lngSecurityDescriptor, _
  229.                                  udtData)
  230.     If lngSubKeysCount > 0 Then
  231.       For lngI = 0 To (lngSubKeysCount - 1)
  232.         strClass = String$(1024, 32)
  233.         lngClass = 1024
  234.         strKeyName = String$(1024, 32)
  235.         lngKeyLenght = 1024
  236.         udtData.dwHighDateTime = 0
  237.         udtData.dwLowDateTime = 0
  238.         TestAPIError RegEnumKeyEx(lngKeyHandle, lngI, _
  239.                                   strKeyName, lngKeyLenght, _
  240.                                   ByVal 0&, strClass, lngClass, udtData)
  241.         ReDim Preserve astrKey(0 To lngI) As String
  242.         astrKey(lngI) = Left(strKeyName, lngKeyLenght)
  243.       Next lngI
  244.       DirKey = astrKey
  245.     Else
  246.       DirKey = Null
  247.     End If
  248.     CdExt CurrentKey, KEY_ALL_ACCESS
  249.   End If
  250.   Exit Function
  251.  
  252. DirKey_Err:
  253.   Err.Raise Err.Number, Err.Source, Err.Description
  254. End Function
  255. Public Function DirValue() As Variant
  256. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 04/05/97 2.17.16
  257. Dim lngValueCount As Long
  258. Dim strValueName As String
  259. Dim lngValueNameLength As Long
  260. Dim lngValueLength As Long
  261. Dim lngValueType As Long
  262. Dim strKeyName As String
  263. Dim lngKeyLenght As Long
  264. Dim lngI As Long
  265. Dim lngJ As Long
  266. Dim lngK As Long
  267. Dim abytValue(1024) As Byte
  268. Dim astrValue() As String
  269. Dim lngTemp As Long
  270. Dim dblTemp As Double
  271. Dim strTemp As String
  272. Dim lngSubKeysCount As Long
  273. Dim lngMaxSubKeyLen As Long
  274. Dim lngMaxClassLen As Long
  275. Dim lngValues As Long
  276. Dim udtData As FILETIME
  277. Dim lngMaxValueNameLen As Long
  278. Dim lngMaxValueLen As Long
  279. Dim lngSecurityDescriptor As Long
  280. On Error GoTo DirKey_Err
  281.   If CurrentKey = "" Then
  282.     DirValue = Null
  283.   Else
  284.     CdExt CurrentKey, KEY_READ
  285.     lngKeyLenght = 1024
  286.     strKeyName = String$(1024, 32)
  287.     lngValueCount = 0
  288.     udtData.dwHighDateTime = 0
  289.     udtData.dwLowDateTime = 0
  290.     TestAPIError RegQueryInfoKey(lngKeyHandle, _
  291.                                  strKeyName, lngKeyLenght, ByVal 0&, _
  292.                                  lngSubKeysCount, _
  293.                                  lngMaxSubKeyLen, lngMaxClassLen, _
  294.                                  lngValueCount, lngMaxValueNameLen, _
  295.                                  lngMaxValueLen, lngSecurityDescriptor, _
  296.                                  udtData)
  297.     If lngValueCount > 0 Then
  298.       For lngI = 0 To (lngValueCount - 1)
  299.         lngValueNameLength = 1024
  300.         strValueName = String$(1024, 32)
  301.         lngValueLength = 1024
  302.         abytValue(1024) = 0
  303.         TestAPIError RegEnumValue(lngKeyHandle, lngI, _
  304.                                   strValueName, lngValueNameLength, ByVal 0&, _
  305.                                   lngValueType, abytValue(0), lngValueLength)
  306.         ReDim Preserve astrValue(0 To 2, 0 To lngI) As String
  307.         astrValue(erValueName, lngI) = Left(strValueName, lngValueNameLength)
  308.         If lngValueLength > 0 Then
  309.           Select Case lngValueType
  310.             Case REG_BINARY
  311.               lngTemp = 0
  312.               astrValue(erValueType, lngI) = erByte
  313.               For lngJ = 0 To lngValueLength - 1
  314.                 astrValue(erValue, lngI) = astrValue(erValue, lngI) & Hex(abytValue(lngJ)) & " "
  315.               Next
  316.               astrValue(erValue, lngI) = Trim(astrValue(erValue, lngI))
  317.             Case REG_DWORD
  318.               dblTemp = 0
  319.               astrValue(erValueType, lngI) = erDWord
  320.               For lngJ = 0 To lngValueLength - 1 Step 2
  321.                 dblTemp = dblTemp + (256& ^ lngJ) * abytValue(lngJ)
  322.                 dblTemp = dblTemp + (256& ^ (lngJ + 1)) * abytValue(lngJ + 1)
  323.                 strTemp = Hex(256& * abytValue(lngValueLength - 1 - lngJ) + _
  324.                               abytValue(lngValueLength - 1 - lngJ - 1))
  325.                 astrValue(erValue, lngI) = astrValue(erValue, lngI) & _
  326.                   String(4 - Len(strTemp), "0") & strTemp
  327.               Next
  328.               astrValue(erValue, lngI) = astrValue(erValue, lngI) & " (" & Format(dblTemp, "0,000,000,000") & ")"
  329.             Case Else
  330.               astrValue(erValueType, lngI) = erSTRING
  331.               For lngJ = 0 To lngValueLength - 2
  332.                 astrValue(erValue, lngI) = astrValue(erValue, lngI) & Chr(abytValue(lngJ))
  333.               Next
  334.           End Select
  335.           'Debug.Print astrValue(0,lngI)
  336.           'Debug.Print astrValue(1,lngI)
  337.           'Debug.Print astrValue(2,lngI)
  338.         End If
  339.       Next lngI
  340.       DirValue = astrValue
  341.     Else
  342.       DirValue = Null
  343.     End If
  344.     CdExt CurrentKey, KEY_ALL_ACCESS
  345.   End If
  346.   Exit Function
  347.  
  348. DirKey_Err:
  349.   Err.Raise Err.Number, Err.Source, Err.Description
  350. End Function
  351. Public Property Let ValueOf(ByVal strValueName As String, lngValueType As enmDataType, ByVal vntValue As Variant)
  352. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 18/05/97 16.35.53
  353. Dim strData As String
  354. Dim strDataTmp As String
  355. Dim lngData As Long
  356. Dim lngI As Long
  357. Dim bytType As Byte
  358.   On Error GoTo ValueOf_Err
  359.    
  360.   Select Case lngValueType
  361.     Case erByte
  362.       bytType = REG_BINARY
  363.       If TypeName(vntValue) <> "Byte()" Then _
  364.         ClassError 3
  365.       If Dimensione(vntValue) <> 1 Then _
  366.         ClassError 3
  367.       lngData = UBound(vntValue) - LBound(vntValue) + 1
  368.       strData = ""
  369.       For lngI = LBound(vntValue) To UBound(vntValue)
  370.         strData = strData & Chr(vntValue(lngI))
  371.       Next
  372.     Case erDWord
  373.       bytType = REG_DWORD
  374.       If TypeName(vntValue) <> "Double" Then _
  375.         ClassError 3
  376.       If CDbl(vntValue) <> Int(CDbl(vntValue)) Then _
  377.         ClassError 3
  378.       vntValue = Int(CDbl(vntValue))
  379.       If vntValue < 0 Or vntValue > 4294967295# Then _
  380.         ClassError 3
  381.       vntValue = Int(CDbl(vntValue))
  382.       ' MSB
  383.       strDataTmp = Chr(Int(vntValue / 256 ^ 3))
  384.       vntValue = vntValue - (256 ^ 3) * Int(vntValue / 256 ^ 3)
  385.       '
  386.       strDataTmp = strDataTmp & Chr(Int(vntValue / 256 ^ 2))
  387.       vntValue = vntValue - (256 ^ 2) * Int(vntValue / 256 ^ 2)
  388.       '
  389.       strDataTmp = strDataTmp & Chr(Int(vntValue / 256))
  390.       vntValue = vntValue - 256 * Int(vntValue / 256)
  391.       ' LSB
  392.       strDataTmp = strDataTmp & Chr(Int(vntValue))
  393.       '
  394.       strData = Mid(strDataTmp, 4, 1) & Mid(strDataTmp, 3, 1) & Mid(strDataTmp, 2, 1) & Mid(strDataTmp, 1, 1)
  395.       lngData = 4
  396.     Case erSTRING
  397.       bytType = REG_SZ
  398.       If TypeName(vntValue) <> "String" Then _
  399.         ClassError 3
  400.       strData = vntValue & Chr(0)
  401.       lngData = Len(strData)
  402.     Case Else
  403.       ClassError 4
  404.   End Select
  405.   TestAPIError RegSetValueEx(lngKeyHandle, _
  406.                              strValueName, 0&, _
  407.                              bytType, strData, lngData)
  408.   Exit Property
  409.  
  410. ValueOf_Err:
  411.   Err.Raise Err.Number, Err.Source, Err.Description
  412. End Property
  413. Public Property Get ValueOf(ByVal strValueName As String, ByRef lngValueType As enmDataType) As Variant
  414. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 18/05/97 16.33.50
  415. Dim strData As String
  416. Dim lngData As Long
  417. Dim lngType As Long
  418. Dim avntData(0 To 2) As Variant
  419. Dim abytData() As Byte
  420. Dim strFormattedData As String
  421. Dim dblData As Double
  422. Dim lngJ As Long
  423. Dim lngK As Long
  424. Dim strTemp As String
  425.  
  426.   On Error GoTo ValueOf_Err
  427.   If CurrentKey <> "" Then _
  428.     CdExt CurrentKey, KEY_READ
  429.   TestAPIError RegQueryValueEx(lngKeyHandle, _
  430.                                strValueName, 0&, _
  431.                                lngType, _
  432.                                strData, lngData)
  433.   strData = String$(lngData, 32)
  434.   TestAPIError RegQueryValueEx(lngKeyHandle, _
  435.                                strValueName, 0&, _
  436.                                lngType, _
  437.                                strData, lngData)
  438.   Select Case lngType
  439.     Case REG_BINARY
  440.       lngValueType = erByte
  441.     Case REG_DWORD
  442.       lngValueType = erDWord
  443.     Case Else
  444.       lngValueType = erSTRING
  445.   End Select
  446.   'ReDim abytData(0 To 0) As Byte
  447.   If lngData > 0 Then
  448.     ReDim abytData(0 To lngData - 1) As Byte
  449.     Select Case lngType
  450.       Case REG_BINARY
  451.         For lngJ = 1 To lngData
  452.           strFormattedData = strFormattedData & _
  453.                              Hex(Asc(Mid(strData, lngJ, 1))) & " "
  454.           abytData(lngJ - 1) = Asc(Mid(strData, lngJ, 1))
  455.         Next
  456.         strFormattedData = Trim(strFormattedData)
  457.         dblData = 0
  458.       Case REG_DWORD
  459.         dblData = 0
  460.         For lngJ = 0 To lngData - 1 Step 2
  461.           dblData = dblData + (256& ^ lngJ) * Asc(Mid(strData, lngJ + 1, 1))
  462.           dblData = dblData + (256& ^ (lngJ + 1)) * Asc(Mid(strData, lngJ + 2, 1))
  463.           strTemp = Hex(256& * Asc(Mid(strData, lngData - lngJ, 1)) + _
  464.                         Asc(Mid(strData, lngData - lngJ - 1, 1)))
  465.           strFormattedData = strFormattedData & String(4 - Len(strTemp), "0") & strTemp
  466.           abytData(lngJ) = Asc(Mid(strData, lngJ + 1, 1))
  467.           abytData(lngJ + 1) = Asc(Mid(strData, lngJ + 2, 1))
  468.         Next
  469.       Case Else
  470.         If Mid(strData, lngData, 1) = vbNullChar Then
  471.           lngData = lngData - 1
  472.           strData = Left(strData, lngData)
  473.         End If
  474.         strFormattedData = strData
  475.         If lngData > 0 Then
  476.           For lngJ = 1 To lngData
  477.             abytData(lngJ - 1) = Asc(Mid(strData, lngJ, 1))
  478.           Next
  479.           ReDim Preserve abytData(0 To lngData - 1) As Byte
  480.         End If
  481.         dblData = 0
  482.     End Select
  483.   End If
  484.   If CurrentKey <> "" Then _
  485.     CdExt CurrentKey, KEY_ALL_ACCESS
  486.   avntData(erStringFormat) = strFormattedData
  487.   avntData(erByteFormat) = abytData
  488.   avntData(erDWordFormat) = dblData
  489.   ValueOf = avntData
  490.   Exit Property
  491.  
  492. ValueOf_Err:
  493.   Err.Raise Err.Number, Err.Source, Err.Description
  494. End Property
  495. Public Sub MakeKey(ByVal strDirectory As String)
  496. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 18/05/97 22.43.29
  497. Dim lngNewKeyHandle As Long
  498. Dim lngMemorySpace As Long
  499. Dim lpSecurityAttributes As SECURITY_ATTRIBUTES
  500.  
  501.   On Error GoTo MakeKey_Err
  502.   lpSecurityAttributes.lpSecurityDescriptor = 0& ' NULL
  503.   TestAPIError RegCreateKeyEx(lngKeyHandle, _
  504.                               strDirectory, _
  505.                               0&, "", REG_OPTION_NON_VOLATILE, _
  506.                               KEY_ALL_ACCESS, _
  507.                               lpSecurityAttributes, _
  508.                               lngNewKeyHandle, _
  509.                               lngMemorySpace)
  510.                             
  511.   
  512.   Exit Sub
  513.  
  514. MakeKey_Err:
  515.   Err.Raise Err.Number, Err.Source, Err.Description
  516. End Sub
  517. Public Sub DeleteKey(ByVal strName As String)
  518. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 18/05/97 22.44.22
  519.   
  520.   On Error GoTo DeleteKey_Err
  521.   TestAPIError RegDeleteKey(lngKeyHandle, strName)
  522.   
  523.   Exit Sub
  524.  
  525. DeleteKey_Err:
  526.   Err.Raise Err.Number, Err.Source, Err.Description
  527. End Sub
  528. Public Sub DeleteValue(ByVal strName As String)
  529. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 18/05/97 22.44.55
  530.   On Error GoTo DeleteValue_Err
  531.   TestAPIError RegDeleteValue(lngKeyHandle, strName)
  532.   
  533.   Exit Sub
  534.  
  535. DeleteValue_Err:
  536.   Err.Raise Err.Number, Err.Source, Err.Description
  537. End Sub
  538. '
  539. ' --------------------------------------------------------------------------
  540. '
  541. Private Sub CdExt(ByVal strDirectory As String, ByVal lngSecurity As Long)
  542. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 03/05/97 23.56.39
  543. Dim lngNewKeyHandle As Long
  544. Dim lngPos As Long
  545.   On Error GoTo CdExt_Err
  546.   strDirectory = Trim(UCase(strDirectory))
  547.   Select Case strDirectory
  548.     Case "\"
  549.       If strCurrentDirectory <> "" Then _
  550.         TestAPIError RegCloseKey(lngKeyHandle)
  551.       strCurrentDirectory = ""
  552.       lngKeyHandle = 0
  553.     Case ".."
  554.       If strCurrentDirectory = "" Then ClassError 1
  555.       lngPos = 1
  556.       Do While InStr(lngPos, strCurrentDirectory, "\") > 0
  557.         lngPos = InStr(lngPos, strCurrentDirectory, "\") + 1
  558.       Loop
  559.       CdExt Mid(strCurrentDirectory, 1, lngPos - 1), lngSecurity
  560.     Case Else ' CdExt <path>
  561.       ' Tolgo l'ultimo carattere "\" (CLS\ => CLS)
  562.       If Right(strDirectory, 1) = "\" And Len(strDirectory) > 1 Then _
  563.         strDirectory = Mid(strDirectory, 1, Len(strDirectory) - 1)
  564.       ' Se manca aggiungo il simbolo di Root "\"
  565.       If strCurrentDirectory = "" And Left(strDirectory, 1) <> "\" Then _
  566.         strDirectory = "\" & strDirectory
  567.       If Left(strDirectory, 1) = "\" Then ' Percorso dalla radice
  568.         If strCurrentDirectory <> "" Then TestAPIError RegCloseKey(lngKeyHandle)
  569.         Select Case strRoot(strDirectory)
  570.           Case "HKEY_CLASSES_ROOT"
  571.             lngKeyHandle = HKEY_CLASSES_ROOT
  572.           Case "HKEY_CURRENT_USER"
  573.             lngKeyHandle = HKEY_CURRENT_USER
  574.           Case "HKEY_LOCAL_MACHINE"
  575.             lngKeyHandle = HKEY_LOCAL_MACHINE
  576.           Case "HKEY_USERS"
  577.             lngKeyHandle = HKEY_USERS
  578.           Case "HKEY_DYN_DATA"
  579.             lngKeyHandle = HKEY_DYN_DATA
  580.           Case "HKEY_CURRENT_CONFIG"
  581.             lngKeyHandle = HKEY_CURRENT_CONFIG
  582.           Case Else
  583.             ClassError 2
  584.         End Select
  585.         strCurrentDirectory = strDirectory
  586.         TestAPIError _
  587.           RegOpenKeyEx _
  588.           (lngKeyHandle, strPath(strCurrentDirectory), 0, lngSecurity, lngNewKeyHandle)
  589.         lngKeyHandle = lngNewKeyHandle
  590.       Else ' Percorso dalla posizione corrente
  591.         'If strCurrentDirectory = "" Then ClassError 1
  592.         strCurrentDirectory = strCurrentDirectory & "\" & strDirectory
  593.         TestAPIError _
  594.           RegOpenKeyEx _
  595.           (lngKeyHandle, strDirectory, 0, lngSecurity, lngNewKeyHandle)
  596.         lngKeyHandle = lngNewKeyHandle
  597.       End If
  598.   End Select
  599.   'Debug.Print strCurrentDirectory, lngKeyHandle
  600.   Exit Sub
  601.  
  602. CdExt_Err:
  603.   Err.Raise Err.Number, Err.Source, Err.Description
  604. End Sub
  605. Private Function strRoot(ByVal strDirectory As String) As String
  606. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 04/05/97 15.52.08
  607.   On Error GoTo strRoot_Err
  608.   ' Precondition : Mid(strDirectory,1,1)="\"
  609.   If InStr(2, strDirectory, "\") <> 0 Then
  610.     strRoot = Mid(strDirectory, 2, InStr(2, strDirectory, "\") - 2)
  611.   Else
  612.     strRoot = Mid(strDirectory, 2)
  613.   End If
  614.   Exit Function
  615.  
  616. strRoot_Err:
  617.   Err.Raise Err.Number, Err.Source, Err.Description
  618. End Function
  619. Private Function strPath(ByVal strDirectory As String) As String
  620. '(ERROR ROUTINE BY-PASS) di Luca Minudel il 04/05/97 15.54.20
  621.   On Error GoTo strPath_Err
  622.   If InStr(2, strDirectory, "\") <> 0 Then
  623.     strPath = Mid(strDirectory, InStr(2, strDirectory, "\") + 1)
  624.   Else
  625.     strPath = ""
  626.   End If
  627.   Exit Function
  628.  
  629. strPath_Err:
  630.   Err.Raise Err.Number, Err.Source, Err.Description
  631. End Function
  632. Private Function Dimensione(ByRef vntMatrice As Variant) As Integer
  633. Dim intContaDimensione As Integer
  634. Dim intNiente As Integer
  635.   intContaDimensione = 0
  636.   On Error GoTo intDimensione_Fine
  637.   Do
  638.     intNiente = UBound(vntMatrice, intContaDimensione + 1)
  639.     intContaDimensione = intContaDimensione + 1
  640.   Loop
  641. intDimensione_Fine:
  642.   Dimensione = intContaDimensione
  643. End Function
  644. Private Sub ClassError(ByVal lngNumber As Long)
  645.   Err.Source = "EasyRegistry"
  646.   Select Case lngNumber
  647.     Case 1
  648.       Err.Description = "No current Key."
  649.     Case 2
  650.       Err.Description = "Invalid Key root."
  651.     Case 3
  652.       Err.Source = Err.Source & " [Let ValueOf]"
  653.       Err.Description = "Type passed doesn't match Value passed."
  654.     Case 4
  655.       Err.Source = Err.Source & " [Let ValueOf]"
  656.       Err.Description = "Type passed doesn't exist. Use STRING, DWORD or BINARY."
  657.     Case Else
  658.       Err.Description = "Undefined error number : " & CStr(vbObject + lngNumber)
  659.       lngNumber = 255
  660.   End Select
  661.   Err.Raise vbObjectError + lngNumber
  662. End Sub
  663. Private Sub TestAPIError(ByVal lngNumber As Long)
  664.   Err.Source = "EasyRegistry[API Call]"
  665.   Select Case lngNumber
  666.     Case ERROR_SUCCESS
  667.       ' Ok !
  668.     Case ERROR_BADDB
  669.       Err.Description = "Corrupt Registry Database!"
  670.     Case ERROR_BADKEY
  671.       Err.Description = "Key name is bad."
  672.     Case ERROR_CANTOPEN
  673.       Err.Description = "Cannot Open Key."
  674.     Case ERROR_CANTREAD
  675.       Err.Description = "Cannot Read Key."
  676.     Case ERROR_CANTWRITE
  677.       Err.Description = "Cannot Write Key."
  678.     Case ERROR_ACCESS_DENIED
  679.       Err.Description = "Access to Registry Denied."
  680.     Case ERROR_OUTOFMEMORY
  681.       Err.Description = "Out of memory."
  682.     Case ERROR_INVALID_PARAMETER
  683.       Err.Description = "Invalid Parameter."
  684.     Case ERROR_FILE_NOT_FOUND
  685.       Err.Description = "Key/Value does not exist."
  686.     Case Else
  687.       Err.Description = "Undefined key error code!"
  688.   End Select
  689.   If lngNumber = ERROR_SUCCESS Then
  690.     Err.Clear
  691.   Else
  692.     Err.Raise vbObjectError + 256
  693.   End If
  694. End Sub
  695.