home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / SDS!_-_Sec1986884132006.psc / clsLightning.cls < prev    next >
Text File  |  2006-04-13  |  63KB  |  1,984 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsLightning"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. '***************************************************************************************
  17. '*  Lightning!   1.6.5 Standalone Registry Control Class                               *
  18. '*                                                                                     *
  19. '*  Created:     November 13, 2005                                                     *
  20. '*  Updated:     April 12, 2006                                                        *
  21. '*  Purpose:     Comprehensive Registry Control Class                                  *
  22. '*  Functions:   (listed)                                                              *
  23. '*  Revision:    1.6.5                                                                 *
  24. '*  Compile:     Native                                                                *
  25. '*  Referenced:  Throughout Project                                                    *
  26. '*  Author:      John Underhill (Steppenwolfe)                                         *
  27. '*                                                                                     *
  28. '***************************************************************************************
  29.  
  30. '/~  List of exposed functions ~/
  31.  
  32. '/~  Value Types ~/
  33. '/~  Access_Check - Test user access rights
  34. '/~  Read_BEndian - read a big endian value
  35. '/~  Write_BEndian - write a big_endian value
  36. '/~  Read_Binary - read a binary value
  37. '/~  Write_Binary - write a binary value
  38. '/~  Read_Dword - read a dword value
  39. '/~  Write_Dword - write a dword value
  40. '/~  Read_Link - read a binary link value
  41. '/~  Write_Link - write a binary link value
  42. '/~  List_Data - list all data blocks in a subkeys values
  43. '/~  List_Values - puts all of a keys values into a collection
  44. '/~  Read_LEndian - read a little endian value
  45. '/~  Write_LEndian - write a little_endian value
  46. '/~  Read_Multi - read a multi_sz value
  47. '/~  Write_Multi - write a multi_sz value
  48. '/~  Read_MultiCN - reads a multi value and splits into a collection
  49. '/~  Write_MultiCN - converts a collection into a multi_sz value
  50. '/~  Write_Qword - write a 64bit dword number
  51. '/~  Read_Qword - read a 64bit dword number
  52. '/~  Read_ResDescriptor - read hardware resource description (hex)binary
  53. '/~  Write_ResDescriptor = write hardware resource description (hex)binary
  54. '/~  Read_ResourceList - read a hardware resource list (hex)binary
  55. '/~  Write_ResourceList - write to a hardware resource list (hex)binary
  56. '/~  Read_ResRequired - read a hardware resource requirements list (hex)binary
  57. '/~  Write_ResRequired - write to a hardware resource requirements list (hex)binary
  58. '/~  Read_String - read a string(sz) or expanded string(expand_sz)
  59. '/~  Write_String - write a string value
  60. '/~  Write_Expanded - write an expanded string value
  61.  
  62. '/~  Key Related Functions ~/
  63. '/~  List_Keys - puts all subkeys under specified branch into a collection
  64. '/~  Key_Exists - test if key exists
  65. '/~  Create_Key - create a new key
  66. '/~  Delete_Key - delete a key
  67.  
  68. '/~  Value Related Functions ~/
  69. '/~  Write_Value - write value types: 1)sz 2)expand_sz 3)multi_sz 4)binary 5)dword 6)little_endian 7)big_endian
  70. '/~  Delete_Value - delete a value
  71. '/~  Search_Value - search for a value under the key
  72.  
  73. '/~  Conversion Routines ~/
  74. '/~  Make_LEndian16 - convert integer to 16bit little_endian
  75. '/~  Make_LEndian32 - convert long to 32bit little_endian
  76. '/~  Make_BEndian32 - convert long to big endian format
  77.  
  78. '/~  Error Logging ~/
  79. '/~  Get_Error - interprets errors passed from dll
  80. '/~  Log_Error - sends errors to a log file
  81.  
  82. Public Event ErrorCond(ByVal sRoutine As String, ByVal sKey As String, ByVal sError As String)
  83.  
  84. '/* time structure
  85. Private Type FILETIME
  86.     dwLowDateTime                              As Long
  87.     dwHighDateTime                             As Long
  88. End Type
  89.  
  90. '/* security structure
  91. Private Type SECURITY_ATTRIBUTES
  92.     nLength                                    As Long
  93.     lpSecurityDescriptor                       As Long
  94.     bInheritHandle                             As Boolean
  95. End Type
  96.  
  97. 'key constants
  98. Public Enum HKEY_Type
  99.     HKEY_CLASSES_ROOT = &H80000000
  100.     HKEY_CURRENT_USER = &H80000001
  101.     HKEY_LOCAL_MACHINE = &H80000002
  102.     HKEY_USERS = &H80000003
  103.     HKEY_PERFORMANCE_DATA = &H80000004
  104.     HKEY_CURRENT_CONFIG = &H80000005
  105.     HKEY_DYN_DATA = &H80000006
  106. End Enum
  107.  
  108. '/* value types
  109. Public Enum Reg_Type
  110.     REG_NONE = 0                            '/* No value type
  111.     REG_SZ = 1                              '/* Unicode NULL terminated string
  112.     REG_EXPAND_SZ = 2                       '/* Unicode NULL terminated string
  113.     REG_BINARY = 3                          '/* Binary data
  114.     REG_DWORD = 4                           '/* 32-bit number
  115.     REG_DWORD_LITTLE_ENDIAN = 4             '/* 32-bit number
  116.     REG_DWORD_BIG_ENDIAN = 5                '/* 32-bit number, high byte first
  117.     REG_LINK = 6                            '/* Unicode symbolic link
  118.     REG_MULTI_SZ = 7                        '/* Array of Unicode strings
  119.     REG_RESOURCE_LIST = 8                   '/* Hardware resource description
  120.     REG_FULL_RESOURCE_DESCRIPTOR = 9        '/* Hardware resource description
  121.     REG_RESOURCE_REQUIREMENTS_LIST = 10     '/* Resource requirements
  122.     REG_QWORD_LITTLE_ENDIAN = 11            '/* 64bit dword value
  123. End Enum
  124.  
  125. '/* access paramaters
  126. Private Const KEY_ALL_ACCESS               As Long = &HF003F
  127. Private Const KEY_CREATE_LINK              As Long = &H20
  128. Private Const KEY_CREATE_SUB_KEY           As Long = &H4
  129. Private Const KEY_ENUMERATE_SUB_KEYS       As Long = &H8
  130. Private Const KEY_EXECUTE                  As Long = &H20019
  131. Private Const KEY_NOTIFY                   As Long = &H10
  132. Private Const KEY_QUERY_VALUE              As Long = &H1
  133. Private Const KEY_READ                     As Long = &H20019
  134. Private Const KEY_SET_VALUE                As Long = &H2
  135. Private Const KEY_WRITE                    As Long = &H20006
  136. Private Const REG_OPTION_NON_VOLATILE      As Long = &H0
  137. Private Const REG_ERR_OK                   As Long = &H0
  138. Private Const REG_ERR_NOT_EXIST            As Long = &H1
  139. Private Const REG_ERR_NOT_STRING           As Long = &H2
  140. Private Const REG_ERR_NOT_DWORD            As Long = &H4
  141.  
  142. '/* error handling
  143. Private Const ERROR_NONE                   As Long = &H0
  144. Private Const ERROR_BADDB                  As Long = &H1
  145. Private Const ERROR_BADKEY                 As Long = &H2
  146. Private Const ERROR_CANTOPEN               As Long = &H3
  147. Private Const ERROR_CANTREAD               As Long = &H4
  148. Private Const ERROR_CANTWRITE              As Long = &H5
  149. Private Const ERROR_OUTOFMEMORY            As Long = &H6
  150. Private Const ERROR_ARENA_TRASHED          As Long = &H7
  151. Private Const ERROR_ACCESS_DENIED          As Long = &H8
  152. Private Const ERROR_INVALID_PARAMETERS     As Long = &H57
  153. Private Const ERROR_MORE_DATA              As Long = &HEA
  154. Private Const ERROR_NO_MORE_ITEMS          As Long = &H103
  155.  
  156. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
  157.                                                                      Source As Any, _
  158.                                                                      ByVal Length As Long)
  159.                                                                      
  160. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, _
  161.                                                                                 ByVal lpSubKey As String, _
  162.                                                                                 ByVal ulOptions As Long, _
  163.                                                                                 ByVal samDesired As Long, _
  164.                                                                                 phkResult As Long) As Long
  165.                                                                                 
  166. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  167.  
  168. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, _
  169.                                                                                       ByVal lpValueName As String, _
  170.                                                                                       ByVal lpReserved As Long, _
  171.                                                                                       lpType As Long, _
  172.                                                                                       lpData As Any, _
  173.                                                                                       lpcbData As Long) As Long
  174.                                                                                       
  175. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, _
  176.                                                                                 ByVal lpSubKey As String) As Long
  177.  
  178. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, _
  179.                                                                                     ByVal lpValueName As String) As Long
  180.  
  181. Private Declare Function RegCreatekey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, _
  182.                                                                                 ByVal lpSubKey As String, _
  183.                                                                                 phkResult As Long) As Long
  184.  
  185. Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, _
  186.                                                                                     ByVal lpSubKey As String, _
  187.                                                                                     ByVal Reserved As Long, _
  188.                                                                                     ByVal lpClass As String, _
  189.                                                                                     ByVal dwOptions As Long, _
  190.                                                                                     ByVal samDesired As Long, _
  191.                                                                                     lpSecurityAttributes As SECURITY_ATTRIBUTES, _
  192.                                                                                     phkResult As Long, _
  193.                                                                                     lpdwDisposition As Long) As Long
  194.  
  195. Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, _
  196.                                                                                   ByVal lpValueName As String, _
  197.                                                                                   ByVal Reserved As Long, _
  198.                                                                                   ByVal dwType As Long, _
  199.                                                                                   lpData As Any, _
  200.                                                                                   ByVal cbData As Long) As Long
  201.  
  202. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, _
  203.                                                                                 ByVal dwIndex As Long, _
  204.                                                                                 ByVal lpName As String, _
  205.                                                                                 lpcbName As Long, _
  206.                                                                                 lpReserved As Long, _
  207.                                                                                 ByVal lpClass As String, _
  208.                                                                                 lpcbClass As Long, _
  209.                                                                                 lpftLastWriteTime As FILETIME) As Long
  210.  
  211. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, _
  212.                                                                                 ByVal dwIndex As Long, _
  213.                                                                                 ByVal lpValueName As String, _
  214.                                                                                 lpcbValueName As Long, _
  215.                                                                                 ByVal lpReserved As Long, _
  216.                                                                                 lpType As Long, _
  217.                                                                                 lpData As Byte, _
  218.                                                                                 lpcbData As Long) As Long
  219.  
  220. Private m_bIntercept    As Boolean
  221. Private m_bLogging      As Boolean
  222. Private m_bNotify       As Boolean
  223.  
  224.  
  225. Public Property Let p_Intercept(PropVal As Boolean)
  226. '/* enable error interception
  227.     m_bIntercept = PropVal
  228. End Property
  229.  
  230. Public Property Let p_Logging(PropVal As Boolean)
  231. '/* enable error logging
  232.     m_bLogging = PropVal
  233. End Property
  234.  
  235. Public Property Let p_Notify(PropVal As Boolean)
  236. '/* enable error notification
  237.     m_bNotify = PropVal
  238. End Property
  239.  
  240.  
  241. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  242. '                                              PROCESSING CORE
  243. '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  244.  
  245.  
  246. Public Function Access_Test(ByVal RootKey As HKEY_Type, _
  247.                             ByVal SubKey As String) As Boolean
  248.  
  249. '/* test user access
  250.  
  251. Dim lHKey           As Long
  252. Dim lRetVal         As Long
  253. Dim lDeposit        As Long
  254. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  255.  
  256. On Error GoTo Handler
  257.  
  258.     '/* security attributes
  259.     With tSecAttrib
  260.         .nLength = Len(tSecAttrib)
  261.         .lpSecurityDescriptor = 0
  262.         .bInheritHandle = 1
  263.     End With
  264.     
  265.     '/* open key
  266.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  267.     If lRetVal = ERROR_NONE Then
  268.         Access_Test = True
  269.     End If
  270.  
  271. Handler:
  272.     If lRetVal <> 0 Then
  273.         If m_bIntercept Then
  274.             Error_State lRetVal, "Access_Test", SubKey
  275.         End If
  276.     End If
  277.     lRetVal = RegCloseKey(lHKey)
  278.     On Error GoTo 0
  279.  
  280. End Function
  281.  
  282. Public Function Read_BEndian(ByVal RootKey As HKEY_Type, _
  283.                              ByVal SubKey As String, _
  284.                              ByVal Value As Variant) As String
  285.  
  286. '/* read an big_endian value
  287. Dim lHKey           As Long
  288. Dim lRetVal         As Long
  289. Dim sBuffer         As String
  290. Dim slength         As Long
  291.  
  292. On Error GoTo Handler
  293.  
  294.     '/* open root key
  295.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  296.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  297.     
  298.     '/* create a buffer
  299.     sBuffer = Space$(255)
  300.     slength = 255
  301.     
  302.     '/* query key for string value
  303.     lRetVal = RegQueryValueEx(lHKey, Value, 0, REG_DWORD_BIG_ENDIAN, ByVal sBuffer, slength)
  304.     
  305.     '/* remove null terminator and add value
  306.     If lRetVal = ERROR_NONE Then
  307.         sBuffer = Left$(sBuffer, slength - 1)
  308.         Read_BEndian = sBuffer
  309.     End If
  310.  
  311. Handler:
  312.     '/* close key and set result
  313.     If lRetVal <> 0 Then
  314.         If m_bIntercept Then
  315.             Error_State lRetVal, "Read_BEndian", SubKey
  316.         End If
  317.     End If
  318.     lRetVal = RegCloseKey(lHKey)
  319.     On Error GoTo 0
  320.  
  321. End Function
  322.  
  323. Public Sub Write_BEndian(ByVal RootKey As HKEY_Type, _
  324.                          ByVal SubKey As String, _
  325.                          ByVal Value As String, _
  326.                          ByVal vData As Variant)
  327.  
  328. '/* write a big endian value (32b number)
  329. Dim lHKey           As Long
  330. Dim lRetVal         As Long
  331. Dim lDeposit        As Long
  332. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  333.  
  334. On Error GoTo Handler
  335.  
  336.     '/* required security structure
  337.     With tSecAttrib
  338.         .nLength = Len(tSecAttrib)
  339.         .lpSecurityDescriptor = 0
  340.         .bInheritHandle = 1
  341.     End With
  342.     
  343.     '/* open key and test access
  344.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  345.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  346.  
  347.     '/* write value, set error, and close key
  348.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_DWORD_BIG_ENDIAN, vData, 4)
  349.  
  350. Handler:
  351.     If lRetVal <> 0 Then
  352.         If m_bIntercept Then
  353.             Error_State lRetVal, "Write_BEndian", SubKey
  354.         End If
  355.     End If
  356.     lRetVal = RegCloseKey(lHKey)
  357.     On Error GoTo 0
  358.  
  359. End Sub
  360.  
  361. Public Function Read_Binary(ByVal RootKey As HKEY_Type, _
  362.                             ByVal SubKey As String, _
  363.                             ByVal Value As Variant) As Variant
  364.  
  365. '/* read a binary value
  366. Dim lHKey           As Long
  367. Dim lRetVal         As Long
  368. Dim byBuffer()      As Byte
  369. Dim lBuffersize     As Long
  370. Dim sTemp           As String
  371. Dim i               As Long
  372.  
  373. On Error GoTo Handler
  374.  
  375.     '/* open root key and test for value type
  376.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  377.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  378.     
  379.     '/* get buffer size
  380.     lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_BINARY, ByVal 0&, lBuffersize)
  381.     
  382.     '/* read into buffer
  383.     If lRetVal = ERROR_NONE Then
  384.         ReDim byBuffer(lBuffersize - 1) As Byte
  385.         lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_BINARY, byBuffer(0), lBuffersize)
  386.         '/* format value
  387.         For i = 0 To UBound(byBuffer)
  388.             sTemp = sTemp & Format$(Trim$(Hex$(byBuffer(i))), "0#")
  389.         Next i
  390.         '/* set value
  391.         Read_Binary = LTrim$(sTemp)
  392.     End If
  393.  
  394. Handler:
  395.     '/* set error and close key
  396.     If lRetVal <> 0 Then
  397.         If m_bIntercept Then
  398.             Error_State lRetVal, "Read_Binary", SubKey
  399.         End If
  400.     End If
  401.     lRetVal = RegCloseKey(lHKey)
  402.     On Error GoTo 0
  403.  
  404. End Function
  405.  
  406. Public Sub Write_Binary(ByVal RootKey As HKEY_Type, _
  407.                         ByVal SubKey As String, _
  408.                         ByVal Value As Variant, _
  409.                         ByRef bData() As Byte)
  410.  
  411. '/* write a binary value
  412. Dim lHKey           As Long
  413. Dim lRetVal         As Long
  414. Dim lDeposit        As Long
  415. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  416.  
  417. On Error GoTo Handler
  418.  
  419.     '/* security structure
  420.     With tSecAttrib
  421.         .nLength = Len(tSecAttrib)
  422.         .lpSecurityDescriptor = 0
  423.         .bInheritHandle = 1
  424.     End With
  425.     
  426.     '/* test access
  427.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  428.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  429.     
  430.     '/* write binary, set error, and close
  431.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_BINARY, bData(0), UBound(bData) + 1)
  432.  
  433. Handler:
  434.     If lRetVal <> 0 Then
  435.         If m_bIntercept Then
  436.             Error_State lRetVal, "Write_Binary", SubKey
  437.         End If
  438.     End If
  439.     lRetVal = RegCloseKey(lHKey)
  440.     On Error GoTo 0
  441.  
  442. End Sub
  443.  
  444. Public Function Read_DWord(ByVal RootKey As HKEY_Type, _
  445.                            ByVal SubKey As String, _
  446.                            ByVal Value As Variant) As Long
  447.  
  448. '/* read a dword value
  449. Dim lHKey           As Long
  450. Dim lRetVal         As Long
  451. Dim lBuffer         As Long
  452.  
  453. On Error GoTo Handler
  454.  
  455.     '/* open root key
  456.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  457.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  458.     
  459.     '/* query value
  460.     lRetVal = RegQueryValueEx(lHKey, Value, 0, REG_DWORD, lBuffer, 4)
  461.     
  462.     '/* set value
  463.     If lRetVal = ERROR_NONE Then
  464.         Read_DWord = lBuffer
  465.     Else
  466.         Read_DWord = 0
  467.     End If
  468.  
  469. Handler:
  470.     '/* close key
  471.     If lRetVal <> 0 Then
  472.         If m_bIntercept Then
  473.             Error_State lRetVal, "Write_Binary", SubKey
  474.         End If
  475.     End If
  476.     lRetVal = RegCloseKey(lHKey)
  477.     On Error GoTo 0
  478.  
  479. End Function
  480.  
  481. Public Sub Write_DWord(ByVal RootKey As HKEY_Type, _
  482.                        ByVal SubKey As String, _
  483.                        ByVal Value As String, _
  484.                        ByVal lData As Long)
  485.  
  486. '/* write a DWORD value
  487. Dim lHKey           As Long
  488. Dim lRetVal         As Long
  489. Dim lDeposit        As Long
  490. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  491.  
  492. On Error GoTo Handler
  493.  
  494.     '/* required security structure
  495.     With tSecAttrib
  496.         .nLength = Len(tSecAttrib)
  497.         .lpSecurityDescriptor = 0
  498.         .bInheritHandle = 1
  499.     End With
  500.     
  501.     '/* open key and test access
  502.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  503.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  504.     
  505.     '/* write value, set error, and close key
  506.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_DWORD, lData, 4)
  507.  
  508. Handler:
  509.     If lRetVal <> 0 Then
  510.         If m_bIntercept Then
  511.             Error_State lRetVal, "Write_DWord", SubKey
  512.         End If
  513.     End If
  514.     lRetVal = RegCloseKey(lHKey)
  515.     On Error GoTo 0
  516.  
  517. End Sub
  518.  
  519. Public Function Read_Link(ByVal RootKey As HKEY_Type, _
  520.                           ByVal SubKey As String, _
  521.                           ByVal Value As Variant) As Variant
  522.  
  523. '/* read a link value
  524. Dim lHKey               As Long
  525. Dim lRetVal             As Long
  526. Dim byBuffer()          As Byte
  527. Dim lBuffersize         As Long
  528.  
  529. On Error GoTo Handler
  530.  
  531.     '/* open root key and test for value type
  532.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  533.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  534.  
  535.     '/* get buffer size
  536.     lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_LINK, ByVal 0&, lBuffersize)
  537.     
  538.     '/* read into buffer
  539.     If lRetVal = ERROR_NONE Then
  540.         ReDim byBuffer(lBuffersize - 1) As Byte
  541.         lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_LINK, byBuffer(0), lBuffersize)
  542.         '/* set value
  543.         Read_Link = byBuffer
  544.     End If
  545.  
  546. Handler:
  547.     '/* set error and close key
  548.     If lRetVal <> 0 Then
  549.         If m_bIntercept Then
  550.             Error_State lRetVal, "Read_Link", SubKey
  551.         End If
  552.     End If
  553.     lRetVal = RegCloseKey(lHKey)
  554.     On Error GoTo 0
  555.  
  556. End Function
  557.  
  558. Public Sub Write_Link(ByVal RootKey As HKEY_Type, _
  559.                       ByVal SubKey As String, _
  560.                       ByVal Value As Variant, _
  561.                       ByRef bData() As Byte)
  562.  
  563. '/* write a link value
  564. Dim lHKey           As Long
  565. Dim lRetVal         As Long
  566. Dim lDeposit        As Long
  567. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  568.  
  569. On Error GoTo Handler
  570.  
  571.     '/* security structure
  572.     With tSecAttrib
  573.         .nLength = Len(tSecAttrib)
  574.         .lpSecurityDescriptor = 0
  575.         .bInheritHandle = 1
  576.     End With
  577.     
  578.     '/* test access
  579.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  580.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  581.  
  582.     '/* write link, set error, and close
  583.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_LINK, bData(0), UBound(bData) + 1)
  584.  
  585. Handler:
  586.     If lRetVal <> 0 Then
  587.         If m_bIntercept Then
  588.             Error_State lRetVal, "Write_Link", SubKey
  589.         End If
  590.     End If
  591.     lRetVal = RegCloseKey(lHKey)
  592.     On Error GoTo 0
  593.  
  594. End Sub
  595.  
  596. Public Function Read_LEndian(ByVal RootKey As HKEY_Type, _
  597.                              ByVal SubKey As String, _
  598.                              ByVal Value As Variant) As Long
  599.  
  600. '/* read a dword value
  601. Dim lHKey           As Long
  602. Dim lRetVal         As Long
  603. Dim lBuffer         As Long
  604.  
  605. On Error GoTo Handler
  606.  
  607.     '/* open root key
  608.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  609.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  610.  
  611.     '/* query value
  612.     lRetVal = RegQueryValueEx(lHKey, Value, 0, REG_DWORD_LITTLE_ENDIAN, lBuffer, 4)
  613.     
  614.     '/* set value
  615.     If lRetVal = ERROR_NONE Then
  616.         Read_LEndian = lBuffer
  617.     Else
  618.         Read_LEndian = 0
  619.     End If
  620.  
  621. Handler:
  622.     '/* close key
  623.     If lRetVal <> 0 Then
  624.         If m_bIntercept Then
  625.             Error_State lRetVal, "Read_LEndian", SubKey
  626.         End If
  627.     End If
  628.     lRetVal = RegCloseKey(lHKey)
  629.     On Error GoTo 0
  630.  
  631. End Function
  632.  
  633. Public Sub Write_LEndian(ByVal RootKey As HKEY_Type, _
  634.                          ByVal SubKey As String, _
  635.                          ByVal Value As String, _
  636.                          ByVal vData As Variant)
  637.  
  638. '/* write a little endian value (same as dword)
  639.  
  640. Dim lHKey           As Long
  641. Dim lRetVal         As Long
  642. Dim lDeposit        As Long
  643. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  644.  
  645. On Error GoTo Handler
  646.  
  647.     '/* required security structure
  648.     With tSecAttrib
  649.         .nLength = Len(tSecAttrib)
  650.         .lpSecurityDescriptor = 0
  651.         .bInheritHandle = 1
  652.     End With
  653.     
  654.     '/* open key and test access
  655.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  656.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  657.  
  658.     '/* write value, set error, and close key
  659.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_DWORD_LITTLE_ENDIAN, vData, 4)
  660.  
  661. Handler:
  662.     If lRetVal <> 0 Then
  663.         If m_bIntercept Then
  664.             Error_State lRetVal, "Write_LEndian", SubKey
  665.         End If
  666.     End If
  667.     lRetVal = RegCloseKey(lHKey)
  668.     On Error GoTo 0
  669.  
  670. End Sub
  671.  
  672. Public Function Read_Multi(ByVal RootKey As HKEY_Type, _
  673.                            ByVal SubKey As String, _
  674.                            ByVal Value As String) As String
  675.  
  676. '/* read a multi_sz value
  677.  
  678. Dim lHKey           As Long
  679. Dim lRetVal         As Long
  680. Dim sBuffer         As String
  681. Dim Length          As Long
  682. Dim resString       As String
  683. Dim resBinary()     As Byte
  684.  
  685. On Error GoTo Handler
  686.  
  687.     '/* open root key
  688.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, &HF003F, lHKey)
  689.     If lRetVal = ERROR_NONE Then
  690.         '/* get buffer size
  691.         Length = 1024
  692.         ReDim resBinary(0 To Length - 1) As Byte
  693.         lRetVal = RegQueryValueEx(lHKey, Value, 0, &H7, resBinary(0), Length)
  694.         '/* if more data, resize our byte array
  695.         If lRetVal = &HEA Then
  696.             ReDim resBinary(0 To Length - 1) As Byte
  697.             lRetVal = RegQueryValueEx(lHKey, Value, 0, &H7, resBinary(0), Length)
  698.         End If
  699.         '/* read into buffer
  700.         If lRetVal = ERROR_NONE Then
  701.             resString = Space$(Length - 2)
  702.             CopyMemory ByVal resString, resBinary(0), Length - 2
  703.             sBuffer = resString
  704.             If Len(Trim_Null(sBuffer)) > 0 Then
  705.                 Read_Multi = resString
  706.             End If
  707.         End If
  708.     End If
  709.  
  710. Handler:
  711.     '/* set error and close key
  712.     If lRetVal <> 0 Then
  713.         If m_bIntercept Then
  714.             Error_State lRetVal, "Read_Multi", SubKey
  715.         End If
  716.     End If
  717.     lRetVal = RegCloseKey(lHKey)
  718.     On Error GoTo 0
  719.  
  720. End Function
  721.  
  722. Public Sub Write_Multi(ByVal RootKey As HKEY_Type, _
  723.                        ByVal SubKey As String, _
  724.                        ByVal Value As String, _
  725.                        ByVal sData As String)
  726.  
  727. '/* write a multi-sz value
  728. Dim lHKey           As Long
  729. Dim lRetVal         As Long
  730. Dim lDeposit        As Long
  731. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  732.  
  733. On Error GoTo Handler
  734.  
  735.     '/* security structure
  736.     With tSecAttrib
  737.         .nLength = Len(tSecAttrib)
  738.         .lpSecurityDescriptor = 0
  739.         .bInheritHandle = 1
  740.     End With
  741.     
  742.     '/* test access
  743.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, &H20006, tSecAttrib, lHKey, lDeposit)
  744.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  745.  
  746.     '/* write multi, set error, and close key
  747.     lRetVal = RegSetValueEx(lHKey, Value, 0, &H7, ByVal sData, Len(sData))
  748.  
  749. Handler:
  750.     If lRetVal <> 0 Then
  751.         If m_bIntercept Then
  752.             Error_State lRetVal, "Write_Multi", SubKey
  753.         End If
  754.     End If
  755.     lRetVal = RegCloseKey(lHKey)
  756.     On Error GoTo 0
  757.  
  758. End Sub
  759.  
  760. Public Function Read_MultiCN(ByVal RootKey As HKEY_Type, _
  761.                              ByVal SubKey As String, _
  762.                              ByVal KeyVal As String) As Collection
  763.  
  764. '//process multi_sz value
  765. '//and return collection
  766. Dim aTemp()         As String
  767. Dim cTemp           As New Collection
  768. Dim sTemp           As String
  769. Dim l               As Long
  770. Dim lReturn         As Long
  771.  
  772. On Error GoTo Handler
  773.  
  774.     Set cTemp = New Collection
  775.     '//get multi string
  776.     sTemp = Read_Multi(RootKey, SubKey, KeyVal)
  777.     If Len(sTemp) = 0 Then GoTo Handler
  778.     
  779.     '//get values and add to collection
  780.     aTemp = Split(sTemp, vbNullChar)
  781.     For l = 0 To UBound(aTemp)
  782.         cTemp.Add aTemp(l)
  783.     Next l
  784.     
  785. Handler:
  786.     '//test for error
  787.     If Not lReturn = 0 Then
  788.         If m_bIntercept Then
  789.             Error_State lReturn, "Read_MultiCN", SubKey
  790.         End If
  791.     Else
  792.         '//set collection and release library
  793.         Set Read_MultiCN = cTemp
  794.         Set cTemp = Nothing
  795.     End If
  796.  
  797. End Function
  798.  
  799. Public Sub Write_MultiCN(ByVal RootKey As HKEY_Type, _
  800.                          ByVal SubKey As String, _
  801.                          ByVal KeyVal As String, _
  802.                          ByVal DataSet As Collection)
  803.  
  804. '//process a collection and
  805. '//write to registry as a
  806. '//multi_sz entry
  807. Dim sTemp           As String
  808. Dim sValue          As String
  809. Dim cTemp           As New Collection
  810. Dim l               As Long
  811. Dim lRetVal         As Long
  812. Dim Item            As Variant
  813.  
  814. On Error GoTo Handler
  815.  
  816.     For Each Item In DataSet
  817.         sTemp = sTemp & Item & vbNullChar
  818.     Next
  819.     '//add terminating null char
  820.     sTemp = sTemp & vbNullChar
  821.     '//write to registry
  822.     Write_Multi RootKey, SubKey, KeyVal, sTemp
  823.     
  824. Handler:
  825.     On Error GoTo 0
  826.  
  827. End Sub
  828.  
  829. Public Function Read_QWord(ByVal RootKey As HKEY_Type, _
  830.                            ByVal SubKey As String, _
  831.                            ByVal Value As Variant) As Currency
  832.  
  833. '/* read a qword value
  834. Dim lHKey           As Long
  835. Dim lRetVal         As Long
  836. Dim lBuffer         As Long
  837.  
  838. On Error GoTo Handler
  839.  
  840.     '/* open root key
  841.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  842.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  843.  
  844.     '/* query value
  845.     lRetVal = RegQueryValueEx(lHKey, Value, 0, REG_QWORD_LITTLE_ENDIAN, lBuffer, 4)
  846.     '/* set value
  847.     If lRetVal = ERROR_NONE Then
  848.         Read_QWord = lBuffer
  849.     Else
  850.         Read_QWord = 0
  851.     End If
  852.  
  853. Handler:
  854.     '/* close key
  855.     If lRetVal <> 0 Then
  856.         If m_bIntercept Then
  857.             Error_State lRetVal, "Read_QWord", SubKey
  858.         End If
  859.     End If
  860.     lRetVal = RegCloseKey(lHKey)
  861.     On Error GoTo 0
  862.  
  863. End Function
  864.  
  865. Public Sub Write_QWord(ByVal RootKey As HKEY_Type, _
  866.                             ByVal SubKey As String, _
  867.                             ByVal Value As String, _
  868.                             ByVal cData As Currency)
  869.  
  870. '/* write a DWORD value
  871. Dim lHKey           As Long
  872. Dim lRetVal         As Long
  873. Dim lDeposit        As Long
  874. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  875.  
  876. On Error GoTo Handler
  877.  
  878.     '/* required security structure
  879.     With tSecAttrib
  880.         .nLength = Len(tSecAttrib)
  881.         .lpSecurityDescriptor = 0
  882.         .bInheritHandle = 1
  883.     End With
  884.     
  885.     '/* open key and test access
  886.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  887.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  888.  
  889.     '/* write value, set error, and close key
  890.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_QWORD_LITTLE_ENDIAN, cData, 4)
  891.  
  892. Handler:
  893.     If lRetVal <> 0 Then
  894.         If m_bIntercept Then
  895.             Error_State lRetVal, "Write_QWord", SubKey
  896.         End If
  897.     End If
  898.     lRetVal = RegCloseKey(lHKey)
  899.     On Error GoTo 0
  900.  
  901. End Sub
  902.  
  903. Public Function Read_ResourceList(ByVal RootKey As HKEY_Type, _
  904.                                   ByVal SubKey As String, _
  905.                                   ByVal Value As Variant) As Variant
  906.  
  907. '/* read a resource list value(binary)
  908. Dim lHKey           As Long
  909. Dim lRetVal         As Long
  910. Dim byBuffer()      As Byte
  911. Dim lBuffersize     As Long
  912.  
  913. On Error GoTo Handler
  914.  
  915.     '/* open root key and test for value type
  916.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  917.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  918.  
  919.     '/* get buffer size
  920.     lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_RESOURCE_LIST, ByVal 0&, lBuffersize)
  921.     
  922.     '/* read into buffer
  923.     If lRetVal = ERROR_NONE Then
  924.         ReDim byBuffer(lBuffersize - 1) As Byte
  925.         lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_RESOURCE_LIST, byBuffer(0), lBuffersize)
  926.         '/* set value
  927.         Read_ResourceList = byBuffer
  928.     End If
  929.  
  930. Handler:
  931.     '/* set error and close key
  932.     If lRetVal <> 0 Then
  933.         If m_bIntercept Then
  934.             Error_State lRetVal, "Read_ResourceList", SubKey
  935.         End If
  936.     End If
  937.     lRetVal = RegCloseKey(lHKey)
  938.     On Error GoTo 0
  939.  
  940. End Function
  941.  
  942. Public Sub Write_ResourceList(ByVal RootKey As HKEY_Type, _
  943.                               ByVal SubKey As String, _
  944.                               ByVal Value As Variant, _
  945.                               ByRef bData() As Byte)
  946.  
  947. '/* write a resource list value(binary)
  948. Dim lHKey           As Long
  949. Dim lRetVal         As Long
  950. Dim lDeposit        As Long
  951. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  952.  
  953. On Error GoTo Handler
  954.  
  955.     '/* security structure
  956.     With tSecAttrib
  957.         .nLength = Len(tSecAttrib)
  958.         .lpSecurityDescriptor = 0
  959.         .bInheritHandle = 1
  960.     End With
  961.     
  962.     '/* test access
  963.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  964.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  965.  
  966.     '/* write resource, set error, and close
  967.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_RESOURCE_LIST, bData(0), UBound(bData) + 1)
  968.  
  969. Handler:
  970.     If lRetVal <> 0 Then
  971.         If m_bIntercept Then
  972.             Error_State lRetVal, "Write_ResourceList", SubKey
  973.         End If
  974.     End If
  975.     lRetVal = RegCloseKey(lHKey)
  976.     On Error GoTo 0
  977.  
  978. End Sub
  979.  
  980. Public Function Read_ResDescriptor(ByVal RootKey As HKEY_Type, _
  981.                                    ByVal SubKey As String, _
  982.                                    ByVal Value As Variant) As Variant
  983.  
  984. '/* read a resource list value(binary)
  985. Dim lHKey           As Long
  986. Dim lRetVal         As Long
  987. Dim byBuffer()      As Byte
  988. Dim lBuffersize     As Long
  989.  
  990. On Error GoTo Handler
  991.  
  992.     '/* open root key and test for value type
  993.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  994.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  995.  
  996.     '/* get buffer size
  997.     lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_FULL_RESOURCE_DESCRIPTOR, ByVal 0&, lBuffersize)
  998.     
  999.     '/* read into buffer
  1000.     If lRetVal = ERROR_NONE Then
  1001.         ReDim byBuffer(lBuffersize - 1) As Byte
  1002.         lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_FULL_RESOURCE_DESCRIPTOR, byBuffer(0), lBuffersize)
  1003.         '/* set value
  1004.         Read_ResDescriptor = byBuffer
  1005.     End If
  1006.  
  1007. Handler:
  1008.     '/* set error and close key
  1009.     If lRetVal <> 0 Then
  1010.         If m_bIntercept Then
  1011.             Error_State lRetVal, "Read_ResDescriptor", SubKey
  1012.         End If
  1013.     End If
  1014.     lRetVal = RegCloseKey(lHKey)
  1015.     On Error GoTo 0
  1016.  
  1017. End Function
  1018.  
  1019. Public Sub Write_ResDescriptor(ByVal RootKey As HKEY_Type, _
  1020.                                ByVal SubKey As String, _
  1021.                                ByVal Value As Variant, _
  1022.                                ByRef bData() As Byte)
  1023.  
  1024. '/* write a resource list value(binary)
  1025. Dim lHKey           As Long
  1026. Dim lRetVal         As Long
  1027. Dim lDeposit        As Long
  1028. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  1029.  
  1030. On Error GoTo Handler
  1031.  
  1032.     '/* security structure
  1033.     With tSecAttrib
  1034.         .nLength = Len(tSecAttrib)
  1035.         .lpSecurityDescriptor = 0
  1036.         .bInheritHandle = 1
  1037.     End With
  1038.     
  1039.     '/* test access
  1040.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  1041.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1042.  
  1043.     '/* write resource, set error, and close
  1044.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_FULL_RESOURCE_DESCRIPTOR, bData(0), UBound(bData) + 1)
  1045.  
  1046. Handler:
  1047.     If lRetVal <> 0 Then
  1048.         If m_bIntercept Then
  1049.             Error_State lRetVal, "Read_ResDescriptor", SubKey
  1050.         End If
  1051.     End If
  1052.     lRetVal = RegCloseKey(lHKey)
  1053.     On Error GoTo 0
  1054.  
  1055. End Sub
  1056.  
  1057. Public Function Read_ResRequired(ByVal RootKey As HKEY_Type, _
  1058.                                  ByVal SubKey As String, _
  1059.                                  ByVal Value As Variant) As Variant
  1060.  
  1061. '/* read a resource requirements value(binary)
  1062. Dim lHKey           As Long
  1063. Dim lRetVal         As Long
  1064. Dim byBuffer()      As Byte
  1065. Dim lBuffersize     As Long
  1066.  
  1067. On Error GoTo Handler
  1068.  
  1069.     '/* open root key and test for value type
  1070.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  1071.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1072.  
  1073.     '/* get buffer size
  1074.     lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_RESOURCE_REQUIREMENTS_LIST, ByVal 0&, lBuffersize)
  1075.     
  1076.     '/* read into buffer
  1077.     If lRetVal = ERROR_NONE Then
  1078.         ReDim byBuffer(lBuffersize - 1) As Byte
  1079.         lRetVal = RegQueryValueEx(lHKey, Value, 0&, REG_RESOURCE_REQUIREMENTS_LIST, byBuffer(0), lBuffersize)
  1080.         '/* set value
  1081.         Read_ResRequired = byBuffer
  1082.     End If
  1083.  
  1084. Handler:
  1085.     '/* set error and close key
  1086.     If lRetVal <> 0 Then
  1087.         If m_bIntercept Then
  1088.             Error_State lRetVal, "Read_ResRequired", SubKey
  1089.         End If
  1090.     End If
  1091.     lRetVal = RegCloseKey(lHKey)
  1092.     On Error GoTo 0
  1093.  
  1094. End Function
  1095.  
  1096. Public Sub Write_ResRequired(ByVal RootKey As HKEY_Type, _
  1097.                              ByVal SubKey As String, _
  1098.                              ByVal Value As Variant, _
  1099.                              ByRef bData() As Byte)
  1100.  
  1101. '/* write a resource requirements value(binary)
  1102. Dim lHKey           As Long
  1103. Dim lRetVal         As Long
  1104. Dim lDeposit        As Long
  1105. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  1106.  
  1107. On Error GoTo Handler
  1108.  
  1109.     '/* security structure
  1110.     With tSecAttrib
  1111.         .nLength = Len(tSecAttrib)
  1112.         .lpSecurityDescriptor = 0
  1113.         .bInheritHandle = 1
  1114.     End With
  1115.     
  1116.     '/* test access
  1117.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  1118.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1119.  
  1120.     '/* write resource, set error, and close
  1121.     lRetVal = RegSetValueEx(lHKey, Value, 0&, REG_RESOURCE_REQUIREMENTS_LIST, bData(0), UBound(bData) + 1)
  1122.  
  1123. Handler:
  1124.     If lRetVal <> 0 Then
  1125.         If m_bIntercept Then
  1126.             Error_State lRetVal, "Write_ResRequired", SubKey
  1127.         End If
  1128.     End If
  1129.     lRetVal = RegCloseKey(lHKey)
  1130.     On Error GoTo 0
  1131.  
  1132. End Sub
  1133.  
  1134. Public Function Read_String(ByVal RootKey As HKEY_Type, _
  1135.                             ByVal SubKey As String, _
  1136.                             ByVal Value As String) As String
  1137.  
  1138. '/* read an SZ value
  1139. Dim lHKey           As Long
  1140. Dim lRetVal         As Long
  1141. Dim sBuffer         As String
  1142. Dim slength         As Long
  1143.  
  1144. On Error GoTo Handler
  1145.  
  1146.     '/* open root key
  1147.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  1148.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1149.     
  1150.     '/* create a buffer
  1151.     sBuffer = Space$(255)
  1152.     slength = 255
  1153.     '/* query key for string value
  1154.     lRetVal = RegQueryValueEx(lHKey, Value, 0, REG_SZ, ByVal sBuffer, slength)
  1155.     
  1156.     '/* read string into buffer
  1157.     If lRetVal = ERROR_NONE Then
  1158.         sBuffer = Left$(sBuffer, slength - 1)
  1159.         Read_String = sBuffer
  1160.     End If
  1161.  
  1162. Handler:
  1163.     '/* close key and set result
  1164.     If lRetVal <> 0 Then
  1165.         If m_bIntercept Then
  1166.             Error_State lRetVal, "Read_String", SubKey
  1167.         End If
  1168.     End If
  1169.     lRetVal = RegCloseKey(lHKey)
  1170.     On Error GoTo 0
  1171.  
  1172. End Function
  1173.  
  1174. Public Sub Write_String(ByVal RootKey As HKEY_Type, _
  1175.                         ByVal SubKey As String, _
  1176.                         ByVal Value As String, _
  1177.                         ByVal Data As String)
  1178.  
  1179. '/* write an SZ value
  1180. Dim lHKey           As Long
  1181. Dim lRetVal         As Long
  1182. Dim lDeposit        As Long
  1183. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  1184.  
  1185. On Error GoTo Handler
  1186.  
  1187.     '/* security attributes
  1188.     With tSecAttrib
  1189.         .nLength = Len(tSecAttrib)
  1190.         .lpSecurityDescriptor = 0
  1191.         .bInheritHandle = 1
  1192.     End With
  1193.     
  1194.     '/* open key
  1195.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  1196.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1197.  
  1198.     '/* write string, set error, and close
  1199.     lRetVal = RegSetValueEx(lHKey, Value, 0, REG_SZ, ByVal Data, Len(Data))
  1200.  
  1201. Handler:
  1202.     If lRetVal <> 0 Then
  1203.         If m_bIntercept Then
  1204.             Error_State lRetVal, "Write_String", SubKey
  1205.         End If
  1206.     End If
  1207.     lRetVal = RegCloseKey(lHKey)
  1208.     On Error GoTo 0
  1209.  
  1210. End Sub
  1211.  
  1212. Public Sub Write_Expanded(ByVal RootKey As HKEY_Type, _
  1213.                           ByVal SubKey As String, _
  1214.                           ByVal Value As String, _
  1215.                           ByVal sData As String)
  1216.  
  1217. '/* write an SZ value
  1218. Dim lHKey           As Long
  1219. Dim lRetVal         As Long
  1220. Dim lDeposit        As Long
  1221. Dim tSecAttrib      As SECURITY_ATTRIBUTES
  1222.  
  1223. On Error GoTo Handler
  1224.  
  1225.     '/* security attributes
  1226.     With tSecAttrib
  1227.         .nLength = Len(tSecAttrib)
  1228.         .lpSecurityDescriptor = 0
  1229.         .bInheritHandle = 1
  1230.     End With
  1231.     
  1232.     '/* open key
  1233.     lRetVal = RegCreateKeyEx(RootKey, SubKey, 0, "", 0, KEY_WRITE, tSecAttrib, lHKey, lDeposit)
  1234.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1235.  
  1236.     '/* write string, set error, and close
  1237.     lRetVal = RegSetValueEx(lHKey, Value, 0, REG_EXPAND_SZ, ByVal sData, Len(sData))
  1238.  
  1239. Handler:
  1240.     If lRetVal <> 0 Then
  1241.         If m_bIntercept Then
  1242.             Error_State lRetVal, "Write_Expanded", SubKey
  1243.         End If
  1244.     End If
  1245.     lRetVal = RegCloseKey(lHKey)
  1246.     On Error GoTo 0
  1247.  
  1248. End Sub
  1249.  
  1250. Public Function Key_Exist(ByVal RootKey As HKEY_Type, _
  1251.                           ByVal SubKey As String) As Boolean
  1252.  
  1253. '/* check for key
  1254. Dim lHKey           As Long
  1255. Dim lRetVal         As Long
  1256.  
  1257. On Error GoTo Handler
  1258.  
  1259.     '/* if 0 returned, key is valid
  1260.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_QUERY_VALUE, lHKey)
  1261.     If lRetVal = ERROR_NONE Then
  1262.         Key_Exist = True
  1263.     End If
  1264.  
  1265. Handler:
  1266.     RegCloseKey lHKey
  1267.     On Error GoTo 0
  1268.  
  1269. End Function
  1270.  
  1271. Public Function Value_Exist(ByVal RootKey As HKEY_Type, _
  1272.                             ByVal SubKey As String, _
  1273.                             ByVal Value As String) As Boolean
  1274.  
  1275. '/* read an SZ value
  1276. Dim lHKey           As Long
  1277. Dim lRetVal         As Long
  1278. Dim sBuffer         As String
  1279. Dim slength         As Long
  1280. Dim DataType        As Long
  1281.  
  1282. On Error GoTo Handler
  1283.  
  1284.     '/* open root key
  1285.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, lHKey)
  1286.     If lRetVal = ERROR_NONE Then
  1287.         '/* create a buffer
  1288.         sBuffer = Space$(255)
  1289.         slength = 255
  1290.         '/* query key for string value
  1291.         lRetVal = RegQueryValueEx(lHKey, Value, 0, DataType, ByVal sBuffer, slength)
  1292.         '/* read string into buffer
  1293.         If lRetVal = ERROR_NONE Then
  1294.             Value_Exist = True
  1295.         End If
  1296.     End If
  1297.  
  1298. Handler:
  1299.     '/* close key and set result
  1300.     lRetVal = RegCloseKey(lHKey)
  1301.     On Error GoTo 0
  1302.  
  1303. End Function
  1304.  
  1305. Public Function Create_Key(ByVal RootKey As HKEY_Type, _
  1306.                            ByVal SubKey As String) As Boolean
  1307.  
  1308. '/* create a new key
  1309. Dim lHKey           As Long
  1310. Dim lRetVal         As Long
  1311.  
  1312. On Error GoTo Handler
  1313.  
  1314.     '/* create the key
  1315.     lRetVal = RegCreatekey(RootKey, SubKey, lHKey)
  1316.  
  1317. Handler:
  1318.     '/* set error and close
  1319.     Create_Key = (lRetVal = 0)
  1320.     lRetVal = RegCloseKey(lHKey)
  1321.     On Error GoTo 0
  1322.  
  1323. End Function
  1324.  
  1325. Public Function Delete_Key(ByVal RootKey As HKEY_Type, _
  1326.                            ByVal SubKey As String) As Boolean
  1327.  
  1328. '/* delete a key
  1329. Dim lRetVal         As Long
  1330.  
  1331. On Error GoTo Handler
  1332.  
  1333.     '/* delete key
  1334.     lRetVal = RegDeleteKey(RootKey, SubKey)
  1335.     '/* set error
  1336.     Delete_Key = (lRetVal = 0)
  1337.  
  1338. Handler:
  1339.     On Error GoTo 0
  1340.  
  1341. End Function
  1342.  
  1343. Public Function Delete_Value(ByVal RootKey As HKEY_Type, _
  1344.                              ByVal SubKey As String, _
  1345.                              ByVal Value As Variant) As Boolean
  1346.  
  1347. '/* delete a value
  1348. Dim lRetVal         As Long
  1349. Dim handle          As Long
  1350.  
  1351. On Error GoTo Handler
  1352.  
  1353.     '/* open key
  1354.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ALL_ACCESS, handle)
  1355.     
  1356.     '/* exit on error
  1357.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1358.  
  1359.     '/* delete value
  1360.     lRetVal = RegDeleteValue(handle, Value)
  1361.     Delete_Value = (lRetVal = 0)
  1362.     
  1363. Handler:
  1364.     '/* set error and close key
  1365.     If lRetVal <> 0 Then
  1366.         If m_bIntercept Then
  1367.             Error_State lRetVal, "Delete_Value", SubKey
  1368.         End If
  1369.     End If
  1370.     lRetVal = RegCloseKey(handle)
  1371.     On Error GoTo 0
  1372.  
  1373. End Function
  1374.  
  1375. Public Function List_Keys(ByVal RootKey As HKEY_Type, _
  1376.                           ByVal SubKey As String) As Collection
  1377.  
  1378. '/* list all keys and add to collection
  1379. Dim KeyName         As String
  1380. Dim keylen          As Long
  1381. Dim classname       As String
  1382. Dim classlen        As Long
  1383. Dim lastwrite       As FILETIME
  1384. Dim lHKey           As Long
  1385. Dim lRetVal         As Long
  1386. Dim Index           As Long
  1387. Dim cTemp           As New Collection
  1388.  
  1389. On Error GoTo Handler
  1390.  
  1391.     Set cTemp = New Collection
  1392.     '/* open key
  1393.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ENUMERATE_SUB_KEYS, lHKey)
  1394.     If Not lRetVal = ERROR_NONE Then
  1395.         Set List_Keys = Nothing
  1396.         GoTo Handler
  1397.     End If
  1398.     Index = 0
  1399.     
  1400.     '/* loop through keys and add to collection
  1401.     Do
  1402.         KeyName = Space$(255)
  1403.         keylen = 255
  1404.         classname = Space$(255)
  1405.         classlen = 255
  1406.         lRetVal = RegEnumKeyEx(lHKey, Index, KeyName, keylen, ByVal 0, classname, classlen, lastwrite)
  1407.         If lRetVal = ERROR_NONE Then
  1408.             KeyName = Left$(KeyName, keylen)
  1409.             cTemp.Add KeyName
  1410.         End If
  1411.         Index = Index + 1
  1412.     Loop Until Not lRetVal = 0
  1413.  
  1414. Handler:
  1415.     '/* set collection and close
  1416.     If cTemp.Count > 0 Then
  1417.         Set List_Keys = cTemp
  1418.     Else
  1419.         If m_bIntercept Then
  1420.             Error_State lRetVal, "List_Keys", SubKey
  1421.         End If
  1422.         Set List_Keys = Nothing
  1423.     End If
  1424.     Set cTemp = Nothing
  1425.     lRetVal = RegCloseKey(lHKey)
  1426.     On Error GoTo 0
  1427.  
  1428. End Function
  1429.  
  1430. Public Function ColList_Keys(ByVal RootKey As HKEY_Type, _
  1431.                              ByVal SubKey As String) As Collection
  1432.  
  1433. '/* list all keys and add to collection
  1434. Dim KeyName         As String
  1435. Dim keylen          As Long
  1436. Dim classname       As String
  1437. Dim classlen        As Long
  1438. Dim lastwrite       As FILETIME
  1439. Dim lHKey           As Long
  1440. Dim lRetVal         As Long
  1441. Dim Index           As Long
  1442. Dim cTemp           As New Collection
  1443.  
  1444. On Error GoTo Handler
  1445.  
  1446.     Set ColList_Keys = New Collection
  1447.     '/* open key
  1448.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_ENUMERATE_SUB_KEYS, lHKey)
  1449.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1450.  
  1451.     Index = 0
  1452.     
  1453.     '/* loop through keys and add to collection
  1454.     Do
  1455.         KeyName = Space$(255)
  1456.         keylen = 255
  1457.         classname = Space$(255)
  1458.         classlen = 255
  1459.         lRetVal = RegEnumKeyEx(lHKey, Index, KeyName, keylen, ByVal 0, classname, classlen, lastwrite)
  1460.         If lRetVal = ERROR_NONE Then
  1461.             KeyName = Left$(KeyName, keylen)
  1462.             ColList_Keys.Add KeyName
  1463.         End If
  1464.         Index = Index + 1
  1465.     Loop Until lRetVal <> 0
  1466.  
  1467. Handler:
  1468.     '/* set collection and close
  1469.     If cTemp.Count > 0 Then
  1470.         Set ColList_Keys = cTemp
  1471.     Else
  1472.         If m_bIntercept Then
  1473.             Error_State lRetVal, "List_Keys", SubKey
  1474.         End If
  1475.         Set ColList_Keys = Nothing
  1476.     End If
  1477.     Set cTemp = Nothing
  1478.     lRetVal = RegCloseKey(lHKey)
  1479.     On Error GoTo 0
  1480.  
  1481. End Function
  1482.  
  1483. Public Function List_Values(ByVal RootKey As HKEY_Type, _
  1484.                             ByVal SubKey As String) As Collection
  1485.  
  1486. '/* list all values and add to a collection
  1487. Dim Value           As String
  1488. Dim ValueLen        As Long
  1489. Dim DataType        As Long
  1490. Dim Data(0 To 254)  As Byte
  1491. Dim DataLen         As Long
  1492. Dim lHKey           As Long
  1493. Dim Index           As Long
  1494. Dim lRetVal         As Long
  1495. Dim cTemp           As New Collection
  1496.  
  1497. On Error GoTo Handler
  1498.  
  1499.     Set cTemp = New Collection
  1500.     '/* open key
  1501.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_QUERY_VALUE, lHKey)
  1502.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1503.  
  1504.     Index = 0
  1505.     '/* loop through values and add to collection
  1506.     Do
  1507.         DataLen = 255
  1508.         Value = Space$(255)
  1509.         ValueLen = 255
  1510.         lRetVal = RegEnumValue(lHKey, Index, Value, ValueLen, 0, DataType, Data(0), DataLen)
  1511.         If lRetVal = ERROR_NONE Then
  1512.             Value = Left$(Value, ValueLen)
  1513.             Select Case DataType
  1514.             Case REG_SZ, REG_EXPAND_SZ
  1515.                 cTemp.Add Value
  1516.             Case REG_MULTI_SZ
  1517.                 cTemp.Add Value
  1518.             Case REG_DWORD, REG_DWORD_LITTLE_ENDIAN
  1519.                 cTemp.Add Value
  1520.             Case REG_BINARY
  1521.                 cTemp.Add Value
  1522.             End Select
  1523.         End If
  1524.         Index = Index + 1
  1525.     Loop Until Not lRetVal = 0
  1526.  
  1527.     '/* set error, collection, and close key
  1528.     Set List_Values = cTemp
  1529.     Set cTemp = Nothing
  1530.     lRetVal = RegCloseKey(lHKey)
  1531.  
  1532. Exit Function
  1533.  
  1534. Handler:
  1535.     If lRetVal <> 0 Then
  1536.         If m_bIntercept Then
  1537.             Error_State lRetVal, "Delete_Value", SubKey
  1538.         End If
  1539.         Set List_Values = Nothing
  1540.     End If
  1541.     On Error GoTo 0
  1542.  
  1543. End Function
  1544.  
  1545. Public Function List_Data(ByVal RootKey As HKEY_Type, _
  1546.                           ByVal SubKey As String) As Collection
  1547.  
  1548. '/* list all data for values in a subkey
  1549. Dim Value           As String
  1550. Dim ValueLen        As Long
  1551. Dim DataType        As Long
  1552. Dim Data(0 To 254)  As Byte
  1553. Dim DataLen         As Long
  1554. Dim lHKey           As Long
  1555. Dim Index           As Long
  1556. Dim lRetVal         As Long
  1557. Dim cTemp           As New Collection
  1558.  
  1559. On Error GoTo Handler
  1560.  
  1561.     Set cTemp = New Collection
  1562.     '/* open key
  1563.     lRetVal = RegOpenKeyEx(RootKey, SubKey, 0, KEY_QUERY_VALUE, lHKey)
  1564.     If Not lRetVal = ERROR_NONE Then GoTo Handler
  1565.  
  1566.     Index = 0
  1567.     '/* loop through values and add to collection
  1568.     Do
  1569.         DataLen = 255
  1570.         Value = Space$(255)
  1571.         ValueLen = 255
  1572.         lRetVal = RegEnumValue(lHKey, Index, Value, ValueLen, 0, DataType, Data(0), DataLen)
  1573.         If lRetVal = ERROR_NONE Then
  1574.             Value = Left$(Value, ValueLen)
  1575.             Select Case DataType
  1576.             Case REG_SZ, REG_EXPAND_SZ
  1577.                 cTemp.Add Read_String(RootKey, SubKey, Value), Value
  1578.             Case REG_MULTI_SZ
  1579.                 cTemp.Add Read_Multi(RootKey, SubKey, Value), Value
  1580.             Case REG_DWORD, REG_DWORD_LITTLE_ENDIAN
  1581.                 cTemp.Add Read_DWord(RootKey, SubKey, Value), Value
  1582.             Case REG_BINARY
  1583.                 cTemp.Add Read_Binary(RootKey, SubKey, Value), Value
  1584.             End Select
  1585.         End If
  1586.         Index = Index + 1
  1587.     Loop Until Not lRetVal = 0
  1588.  
  1589.     '/* set error, collection, and close key
  1590.     Set List_Data = cTemp
  1591.     Set cTemp = Nothing
  1592.     lRetVal = RegCloseKey(lHKey)
  1593.  
  1594. Exit Function
  1595.  
  1596. Handler:
  1597.     If lRetVal <> 0 Then
  1598.         If m_bIntercept Then
  1599.             Error_State lRetVal, "Delete_Value", SubKey
  1600.         End If
  1601.         Set List_Data = Nothing
  1602.     End If
  1603.     On Error GoTo 0
  1604.  
  1605. End Function
  1606.  
  1607.  
  1608. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1609. '                                           PERIPHERAL ROUTINES
  1610. '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1611.  
  1612. Public Function Search_Value(ByVal RootKey As HKEY_Type, _
  1613.                              ByVal KeyVal As String, _
  1614.                              ByVal SearchVal As String) As Boolean
  1615.  
  1616. '/* search for a value
  1617. Dim Item            As Variant
  1618. Dim lReturn         As Long
  1619.  
  1620. On Error GoTo Handler
  1621.     
  1622.     '/* enumerate values and compare
  1623.     '/* to search item
  1624.     For Each Item In List_Values(RootKey, KeyVal)
  1625.         If LCase$(Item) = SearchVal Then
  1626.             Search_Value = True
  1627.             Exit For
  1628.         End If
  1629.     Next Item
  1630.     
  1631.     '/* log errors
  1632.     If Not lReturn = 0 Then Get_Error lReturn
  1633.         
  1634. Handler:
  1635. On Error GoTo 0
  1636.     
  1637. End Function
  1638.  
  1639. Public Function Value_Exists(ByVal RootKey As HKEY_Type, _
  1640.                              ByVal SubKey As String, _
  1641.                              ByVal KeyVal As String) As Boolean
  1642.  
  1643. '/* test for key
  1644. On Error GoTo Handler
  1645.  
  1646.     '/* if no error then key exists
  1647.     If Value_Exist(RootKey, SubKey, KeyVal) Then
  1648.         Value_Exists = True
  1649.     End If
  1650.  
  1651. Handler:
  1652. On Error GoTo 0
  1653.  
  1654. End Function
  1655.  
  1656. Public Sub Write_Value(ByVal RootKey As HKEY_Type, _
  1657.                             ByVal SubKey As String, _
  1658.                             ByVal KeyVal As String, _
  1659.                             ByVal ValData As String, _
  1660.                             ByVal DataType As Integer)
  1661.  
  1662. '/* create a new value with data
  1663. '/* supports sz, multi_sz, expand_sz
  1664. '/* binary, dword, little_endian
  1665. '/* big_endian and link
  1666. Dim j               As Integer
  1667. Dim lData           As Long
  1668. Dim MByte()         As Byte
  1669. Dim Btemp()         As String
  1670. Dim lReturn         As Long
  1671.  
  1672. On Error GoTo Handler
  1673.  
  1674.         Select Case DataType
  1675.             Case 1
  1676.                 '/* sz
  1677.                 Write_String RootKey, SubKey, KeyVal, ValData
  1678.         
  1679.             Case 2
  1680.                 '/* expand_sz
  1681.                 Write_Expanded RootKey, SubKey, KeyVal, ValData
  1682.             
  1683.             Case 3
  1684.                 '/* multi_sz
  1685.                 Write_Multi RootKey, SubKey, KeyVal, ValData
  1686.             
  1687.             Case 4
  1688.                 '/* binary
  1689.                 Btemp() = Split(ValData, " ")
  1690.                 For j = 0 To UBound(Btemp) - 1
  1691.                     ReDim Preserve MByte(j)
  1692.                     MByte(j) = CByte(Btemp(j))
  1693.                 Next j
  1694.                 Write_Binary RootKey, SubKey, KeyVal, MByte
  1695.         
  1696.             Case 5
  1697.                 '/* dword
  1698.                 lData = CLng(ValData)
  1699.                 Write_DWord RootKey, SubKey, KeyVal, lData
  1700.     
  1701.             Case 6
  1702.                 '/* little_endian
  1703.                 Write_LEndian RootKey, SubKey, KeyVal, lData
  1704.             
  1705.             Case 7
  1706.                 '/* big_endian
  1707.                 Write_BEndian RootKey, SubKey, KeyVal, lData
  1708.         End Select
  1709.     
  1710.     Erase Btemp
  1711.     Erase MByte
  1712.  
  1713. Handler:
  1714. On Error GoTo 0
  1715.  
  1716. End Sub
  1717.  
  1718. Public Function Trim_Null(Item As String) As String
  1719.  
  1720. '/* trim nulls
  1721.  
  1722. Dim pos             As Integer
  1723.  
  1724. On Error GoTo Handler
  1725.     '/* trim nulls for sz_multi
  1726.     pos = InStr(Item, vbNullChar)
  1727.     If pos Then
  1728.         Item = Left$(Item, pos - 1)
  1729.     End If
  1730.     Trim_Null = Item
  1731.  
  1732. Handler:
  1733.     On Error GoTo 0
  1734.  
  1735. End Function
  1736.  
  1737. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1738. '                                           CONVERSION ROUTINES
  1739. '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1740.  
  1741. '/*  Thanks go out to actorics.de PSC submission
  1742.  
  1743. Private Function Low_Byte(ByVal iNum As Integer) As Byte
  1744.  
  1745. On Error GoTo Handler
  1746.  
  1747.     Low_Byte = iNum And &HFF
  1748.  
  1749. Handler:
  1750.     On Error GoTo 0
  1751.  
  1752. End Function
  1753.  
  1754. Private Function High_Byte(ByVal iNum As Integer) As Byte
  1755.  
  1756. On Error GoTo Handler
  1757.  
  1758.     High_Byte = (iNum And &HFF00&) \ 256
  1759.  
  1760. Handler:
  1761.     On Error GoTo 0
  1762.  
  1763. End Function
  1764.  
  1765. Private Function Make_Word(ByVal bLow As Byte, ByVal bHigh As Byte) As Integer
  1766.  
  1767. On Error GoTo Handler
  1768.  
  1769.     If bHigh And &H80 Then
  1770.         Make_Word = ((bHigh * 256&) + bLow) Or &HFFFF0000
  1771.     Else
  1772.         Make_Word = (bHigh * 256) + bLow
  1773.     End If
  1774.  
  1775. Handler:
  1776.     On Error GoTo 0
  1777.  
  1778. End Function
  1779.  
  1780. Public Function Make_LEndian16(ByVal iVal As Integer) As Integer
  1781. '/* create a 16bit little_endian
  1782. On Error GoTo Handler
  1783.  
  1784. Dim B(1)            As Byte
  1785.  
  1786.     B(0) = Low_Byte(iVal)
  1787.     B(1) = High_Byte(iVal)
  1788.     Make_LEndian16 = Make_Word(B(1), B(0))
  1789.  
  1790. Handler:
  1791.     On Error GoTo 0
  1792.  
  1793. End Function
  1794.  
  1795. Public Function Make_LEndian32(lVal As Long) As String
  1796. '/* create 32bit little_endian
  1797.  
  1798. Dim b0              As Byte
  1799. Dim B1              As Byte
  1800. Dim B2              As Byte
  1801. Dim b3              As Byte
  1802.  
  1803. On Error GoTo Handler
  1804.  
  1805.     b0 = (lVal And &HFF&)
  1806.     B1 = (lVal And &HFF00&) \ &H100&
  1807.     B2 = (lVal And &HFF0000) \ &H10000
  1808.     b3 = (lVal And &H7F000000) \ &H1000000 - 128 * (lVal < 0)
  1809.     Make_LEndian32 = Chr(b0) & Chr(B1) & Chr(B2) & Chr(b3)
  1810.  
  1811. Handler:
  1812.     On Error GoTo 0
  1813.  
  1814. End Function
  1815.  
  1816. Public Function Make_BEndian32(lVal As Long) As String
  1817. '/* create 32bit big_endian
  1818.  
  1819. Dim b0              As Byte
  1820. Dim B1              As Byte
  1821. Dim B2              As Byte
  1822. Dim b3              As Byte
  1823.  
  1824. On Error GoTo Handler
  1825.  
  1826.     b0 = (lVal And &HFF&)
  1827.     B1 = (lVal And &HFF00&) \ &H100&
  1828.     B2 = (lVal And &HFF0000) \ &H10000
  1829.     b3 = (lVal And &H7F000000) \ &H1000000 - 128 * (lVal < 0)
  1830.     Make_BEndian32 = Chr(b3) & Chr(B2) & Chr(B1) & Chr(b0)
  1831.  
  1832. Handler:
  1833.     On Error GoTo 0
  1834.  
  1835. End Function
  1836.  
  1837. Public Function Convert_Unicode(ByVal sWord As String) As Variant
  1838. '/* convert ascii to unicode
  1839.  
  1840. On Error GoTo Handler
  1841.  
  1842.     Convert_Unicode = StrConv(sWord, vbUnicode)
  1843.     
  1844. Handler:
  1845.     On Error GoTo 0
  1846.  
  1847. End Function
  1848.  
  1849. Public Function Convert_Byte(ByVal sVal As String) As Byte
  1850. '/* convert string to byte array
  1851.  
  1852. Dim bVal()          As Byte
  1853. Dim i               As Long
  1854.  
  1855. On Error GoTo Handler
  1856.  
  1857.     ReDim bVal(0 To Len(sVal))
  1858.     For i = 0 To UBound(bVal())
  1859.         bVal(i) = Mid$(sVal, i, 1)
  1860.     Next i
  1861.     
  1862. Handler:
  1863.     On Error GoTo 0
  1864.  
  1865. End Function
  1866.  
  1867. Public Function Convert_Curr(ByVal sValue As String) As Currency
  1868.  
  1869. Dim l               As Long
  1870. Dim Negative        As Boolean
  1871.  
  1872.     sValue = Trim$(sValue)
  1873.     If Left$(sValue, 1) = "-" Then
  1874.         Negative = True
  1875.         sValue = Mid$(sValue, 2)
  1876.     End If
  1877.     
  1878.     l = Len(sValue)
  1879.     If l < 4 Then
  1880.         Convert_Curr = CCur(IIf(Negative, "-0.", "0.") & Right$("0000" & sValue, 4))
  1881.     Else
  1882.         Convert_Curr = CCur(IIf(Negative, "-", "") & Left$(sValue, l - 4) & "." & Right$(sValue, 4))
  1883.     End If
  1884.     
  1885. End Function
  1886.  
  1887. Public Function Convert_Text(ByVal cValue As Currency) As String
  1888.  
  1889. Dim Temp            As String
  1890. Dim l               As Long
  1891.  
  1892.     Temp = Format$(cValue, "#.0000")
  1893.     l = Len(Temp)
  1894.     Temp = Left$(Temp, l - 5) & Right$(Temp, 4)
  1895.     
  1896.     Do While Len(Temp) > 1 And Left$(Temp, 1) = "0"
  1897.         Temp = Mid$(Temp, 2)
  1898.     Loop
  1899.     
  1900.     Do While Len(Temp) > 2 And Left$(Temp, 2) = "-0"
  1901.         Temp = "-" & Mid$(Temp, 3)
  1902.     Loop
  1903.     
  1904.     Temp = Temp / 10000
  1905.     Convert_Text = Temp
  1906.         
  1907. End Function
  1908.  
  1909.  
  1910. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1911. '                                           ERROR LOGGING
  1912. '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1913.  
  1914.  
  1915. Private Sub Error_State(ByVal lErrNum As Long, _
  1916.                         ByVal sRoutine As String, _
  1917.                         ByVal sKey As String)
  1918.  
  1919. '/* send the error to log,
  1920. '/* and raise notification
  1921.  
  1922. Dim sErrDesc        As String
  1923.  
  1924.     sErrDesc = Get_Error(lErrNum)
  1925.     If m_bIntercept Then
  1926.         Log_Error "Description: " + sErrDesc + " Routine: " + " Location: " + sKey
  1927.     End If
  1928.     If m_bNotify Then
  1929.         RaiseEvent ErrorCond(sRoutine, sKey, sErrDesc)
  1930.     End If
  1931.  
  1932. End Sub
  1933.  
  1934. Private Function Get_Error(ByVal lErrNum As Long) As String
  1935. '/* interpret registry errors
  1936.  
  1937. On Error GoTo Handler
  1938.  
  1939.     Select Case lErrNum
  1940.     Case 1
  1941.         Get_Error = "Error: " & lErrNum & " Bad Database. The database is invalid"
  1942.     Case 2
  1943.         Get_Error = "Error: " & lErrNum & " Bad Key Name. Key is corrupt or does not exist"
  1944.     Case 3
  1945.         Get_Error = "Error: " & lErrNum & " Key Locked. The key requested does not exist"
  1946.     Case 4
  1947.         Get_Error = "Error: " & lErrNum & " Failed Read. The key requested can not be read accessed"
  1948.     Case 5
  1949.         Get_Error = "Error: " & lErrNum & " Failed Write. The key requested can not be write accessed"
  1950.     Case 6
  1951.         Get_Error = "Error: " & lErrNum & " Out Of Memory. The process has exceeded its memory allocation"
  1952.     Case 7
  1953.         Get_Error = "Error: " & lErrNum & " Work Area Invalid. The process work area appears to be corrupt"
  1954.     Case 8
  1955.         Get_Error = "Error: " & lErrNum & " Access Is Denied. Access to this key has been denied"
  1956.     Case 87
  1957.         Get_Error = "Error: " & lErrNum & " Invalid Parameters. The call parameters passed are invalid"
  1958.     Case 234
  1959.         Get_Error = "Error: " & lErrNum & " More Data. The container has more data"
  1960.     Case 259
  1961.         Get_Error = "Error: " & lErrNum & " No More Items. No more items for this query"
  1962.     Case Else
  1963.         Get_Error = "Error: An Unknown Error has occured"
  1964.     End Select
  1965.  
  1966. Handler:
  1967.     On Error GoTo 0
  1968.  
  1969. End Function
  1970.  
  1971. Private Sub Log_Error(ByVal ErrDesc As String)
  1972. '/* log errors
  1973.  
  1974. On Error Resume Next
  1975.  
  1976.     '/* write to log
  1977.     Open App.Path & "\err.log" For Append As #1
  1978.         Print #1, CStr(Now) & vbTab & ErrDesc
  1979.     Close #1
  1980.  
  1981. On Error GoTo 0
  1982.  
  1983. End Sub
  1984.