home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / COMMON / RTFAPI.ZIP / Api_VB / INFCOMP2.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-08-10  |  4.2 KB  |  126 lines

  1. Attribute VB_Name = "InfComp2"
  2. Option Explicit
  3.  
  4. Global Const REG_SZ As Long = 1
  5. Global Const REG_DWORD As Long = 4
  6.  
  7. Global Const HKEY_CLASSES_ROOT = &H80000000
  8. Global Const HKEY_CURRENT_USER = &H80000001
  9. Global Const HKEY_LOCAL_MACHINE = &H80000002
  10. Global Const HKEY_USERS = &H80000003
  11.  
  12. Global Const ERROR_NONE = 0
  13. Global Const ERROR_BADDB = 1
  14. Global Const ERROR_BADKEY = 2
  15. Global Const ERROR_CANTOPEN = 3
  16. Global Const ERROR_CANTREAD = 4
  17. Global Const ERROR_CANTWRITE = 5
  18. Global Const ERROR_OUTOFMEMORY = 6
  19. Global Const ERROR_INVALID_PARAMETER = 7
  20. Global Const ERROR_ACCESS_DENIED = 8
  21. Global Const ERROR_INVALID_PARAMETERS = 87
  22. Global Const ERROR_NO_MORE_ITEMS = 259
  23.  
  24. Global Const KEY_ALL_ACCESS = &H3F
  25.  
  26. Global Const REG_OPTION_NON_VOLATILE = 0
  27.  
  28. Declare Function RegCloseKey Lib "advapi32.dll" _
  29. (ByVal hKey As Long) As Long
  30.  
  31. Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
  32. "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  33. ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
  34. As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
  35. As Long, phkResult As Long, lpdwDisposition As Long) As Long
  36.  
  37. Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
  38. "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  39. ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
  40. Long) As Long
  41.  
  42. Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
  43. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  44. String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  45. As String, lpcbData As Long) As Long
  46.  
  47. Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
  48. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  49. String, ByVal lpReserved As Long, lpType As Long, lpData As _
  50. Long, lpcbData As Long) As Long
  51.  
  52. Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
  53. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  54. String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  55. As Long, lpcbData As Long) As Long
  56.  
  57. Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
  58. "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
  59. ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
  60. String, ByVal cbData As Long) As Long
  61.  
  62. Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
  63. "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
  64. ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
  65. ByVal cbData As Long) As Long
  66.  
  67.  
  68. Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
  69. lType As Long, vValue As Variant) As Long
  70.     Dim lValue As Long
  71.     Dim sValue As String
  72.     Select Case lType
  73.         Case REG_SZ
  74.             sValue = vValue & Chr$(0)
  75.             SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
  76.                                            lType, sValue, Len(sValue))
  77.         Case REG_DWORD
  78.             lValue = vValue
  79.             SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
  80. lType, lValue, 4)
  81.         End Select
  82. End Function
  83.  
  84. Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
  85. String, vValue As Variant) As Long
  86.     Dim cch As Long
  87.     Dim lrc As Long
  88.     Dim lType As Long
  89.     Dim lValue As Long
  90.     Dim sValue As String
  91.  
  92.     On Error GoTo QueryValueExError
  93.  
  94.     ' Determine the size and type of data to be read
  95.     lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
  96.     If lrc <> ERROR_NONE Then Error 5
  97.  
  98.     Select Case lType
  99.         ' For strings
  100.         Case REG_SZ:
  101.             sValue = String(cch, 0)
  102. lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _
  103. sValue, cch)
  104.             If lrc = ERROR_NONE Then
  105.                 vValue = Left$(sValue, cch)
  106.             Else
  107.                 vValue = Empty
  108.             End If
  109.         ' For DWORDS
  110.         Case REG_DWORD:
  111. lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, _
  112. lValue, cch)
  113.             If lrc = ERROR_NONE Then vValue = lValue
  114.         Case Else
  115.             'all other data types not supported
  116.             lrc = -1
  117.     End Select
  118.  
  119. QueryValueExExit:
  120.     QueryValueEx = lrc
  121.     Exit Function
  122. QueryValueExError:
  123.     Resume QueryValueExExit
  124. End Function
  125.  
  126.