home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD7555792000.psc / VBRecentProjects / clsRegistry.cls next >
Encoding:
Visual Basic class definition  |  2000-06-14  |  21.0 KB  |  597 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 = "clsRegistry"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14.  
  15. Option Explicit
  16.  
  17. ' =========================================================
  18. ' Class:    cRegistry
  19. ' Author:   Steve McMahon, some little modifications made by me ...
  20. ' Date  :   21 Feb 1997
  21. '
  22. ' A nice class wrapper around the registry functions
  23. ' Allows searching,deletion,modification and addition
  24. ' of Keys or Values.
  25. '
  26. ' Updated 29 April 1998 for VB5.
  27. '   * Fixed GPF in EnumerateValues
  28. '   * Added support for all registry types, not just strings
  29. '   * Put all declares in local class
  30. '   * Added VB5 Enums
  31. '   * Added CreateKey and DeleteKey methods
  32. '
  33. ' Updated 2 January 1999
  34. '   * The CreateExeAssociation method failed to set up the
  35. '     association correctly if the optional document icon
  36. '     was not provided.
  37. '   * Added new parameters to CreateExeAssociation to set up
  38. '     other standard handlers: Print, Add, New
  39. '   * Provided the CreateAdditionalEXEAssociations method
  40. '     to allow non-standard menu items to be added (for example,
  41. '     right click on a .VBP file.  VB installs Run and Make
  42. '     menu items).
  43. '
  44. ' Updated 8 February 2000
  45. '   * Ensure CreateExeAssociation and related items sets up the
  46. '     registry keys in the
  47. '           HKEY_LOCAL_MACHINE\SOFTWARE\Classes
  48. '     branch as well as the HKEY_CLASSES_ROOT branch.
  49. '
  50. ' ---------------------------------------------------------------------------
  51. ' vbAccelerator - free, advanced source code for VB programmers.
  52. '     http://vbaccelerator.com
  53. ' =========================================================
  54.  
  55. 'Registry Specific Access Rights
  56. Private Const KEY_QUERY_VALUE = &H1
  57. Private Const KEY_SET_VALUE = &H2
  58. Private Const KEY_CREATE_SUB_KEY = &H4
  59. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  60. Private Const KEY_NOTIFY = &H10
  61. Private Const KEY_CREATE_LINK = &H20
  62. Private Const KEY_ALL_ACCESS = &H3F
  63.  
  64. 'Open/Create Options
  65. Private Const REG_OPTION_NON_VOLATILE = 0&
  66. Private Const REG_OPTION_VOLATILE = &H1
  67.  
  68. 'Key creation/open disposition
  69. Private Const REG_CREATED_NEW_KEY = &H1
  70. Private Const REG_OPENED_EXISTING_KEY = &H2
  71.  
  72. 'masks for the predefined standard access types
  73. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  74. Private Const SPECIFIC_RIGHTS_ALL = &HFFFF
  75.  
  76. 'Define severity codes
  77. Private Const ERROR_SUCCESS = 0&
  78. Private Const ERROR_ACCESS_DENIED = 5
  79. Private Const ERROR_INVALID_DATA = 13&
  80. Private Const ERROR_MORE_DATA = 234 '  dderror
  81. Private Const ERROR_NO_MORE_ITEMS = 259
  82.  
  83. 'Structures Needed For Registry Prototypes
  84. Private Type SECURITY_ATTRIBUTES
  85.   nLength As Long
  86.   lpSecurityDescriptor As Long
  87.   bInheritHandle As Boolean
  88. End Type
  89.  
  90. Private Type FILETIME
  91.   dwLowDateTime As Long
  92.   dwHighDateTime As Long
  93. End Type
  94.  
  95. 'Registry Function Prototypes
  96. Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
  97.   (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
  98.   ByVal samDesired As Long, phkResult As Long) As Long
  99.  
  100. Private Declare Function RegSetValueExStr Lib "advapi32" Alias "RegSetValueExA" _
  101.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
  102.    ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
  103. Private Declare Function RegSetValueExLong Lib "advapi32" Alias "RegSetValueExA" _
  104.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
  105.    ByVal dwType As Long, szData As Long, ByVal cbData As Long) As Long
  106. Private Declare Function RegSetValueExByte Lib "advapi32" Alias "RegSetValueExA" _
  107.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
  108.    ByVal dwType As Long, szData As Byte, ByVal cbData As Long) As Long
  109.  
  110. Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
  111.  
  112. Private Declare Function RegQueryValueExStr Lib "advapi32" Alias "RegQueryValueExA" _
  113.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
  114.    ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As Long) As Long
  115. Private Declare Function RegQueryValueExLong Lib "advapi32" Alias "RegQueryValueExA" _
  116.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
  117.    ByRef lpType As Long, szData As Long, ByRef lpcbData As Long) As Long
  118. Private Declare Function RegQueryValueExByte Lib "advapi32" Alias "RegQueryValueExA" _
  119.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
  120.    ByRef lpType As Long, szData As Byte, ByRef lpcbData As Long) As Long
  121.    
  122. Private Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" _
  123.   (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, _
  124.    ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, _
  125.    lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, _
  126.    lpdwDisposition As Long) As Long
  127.  
  128. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
  129.   (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
  130.    lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, _
  131.    lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
  132.  
  133. Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" ( _
  134.     ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
  135.     ByVal cbName As Long) As Long
  136.  
  137. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" _
  138.   (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
  139.    lpcbValueName As Long, ByVal lpReserved As Long, ByVal lpType As Long, _
  140.    ByVal lpData As Long, ByVal lpcbData As Long) As Long
  141.    
  142. Private Declare Function RegEnumValueLong Lib "advapi32.dll" Alias "RegEnumValueA" _
  143.   (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
  144.    lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, _
  145.    lpData As Long, lpcbData As Long) As Long
  146. Private Declare Function RegEnumValueStr Lib "advapi32.dll" Alias "RegEnumValueA" _
  147.   (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
  148.    lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, _
  149.    ByVal lpData As String, lpcbData As Long) As Long
  150. Private Declare Function RegEnumValueByte Lib "advapi32.dll" Alias "RegEnumValueA" _
  151.   (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
  152.    lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, _
  153.    lpData As Byte, lpcbData As Long) As Long
  154.  
  155. Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" _
  156.    (ByVal hKey As Long, ByVal lpClass As String, _
  157.    lpcbClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, _
  158.    lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, _
  159.    lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, _
  160.    lpftLastWriteTime As Any) As Long
  161.  
  162. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
  163.   (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  164.  
  165. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
  166.   (ByVal hKey As Long, ByVal lpValueName As String) As Long
  167.  
  168. ' Other declares:
  169. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  170.     lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
  171. Private Declare Function ExpandEnvironmentStrings Lib "kernel32" Alias "ExpandEnvironmentStringsA" (ByVal lpSrc As String, ByVal lpDst As String, ByVal nSize As Long) As Long
  172.  
  173. Public Enum ERegistryClassConstants
  174.     HKEY_CLASSES_ROOT = &H80000000
  175.     HKEY_CURRENT_USER = &H80000001
  176.     HKEY_LOCAL_MACHINE = &H80000002
  177.     HKEY_USERS = &H80000003
  178. End Enum
  179.  
  180. Public Enum ERegistryValueTypes
  181. 'Predefined Value Types
  182.     REG_NONE = (0)                         'No value type
  183.     REG_SZ = (1)                           'Unicode nul terminated string
  184.     REG_EXPAND_SZ = (2)                    'Unicode nul terminated string w/enviornment var
  185.     REG_BINARY = (3)                       'Free form binary
  186.     REG_DWORD = (4)                        '32-bit number
  187.     REG_DWORD_LITTLE_ENDIAN = (4)          '32-bit number (same as REG_DWORD)
  188.     REG_DWORD_BIG_ENDIAN = (5)             '32-bit number
  189.     REG_LINK = (6)                         'Symbolic Link (unicode)
  190.     REG_MULTI_SZ = (7)                     'Multiple Unicode strings
  191.     REG_RESOURCE_LIST = (8)                'Resource list in the resource map
  192.     REG_FULL_RESOURCE_DESCRIPTOR = (9)     'Resource list in the hardware description
  193.     REG_RESOURCE_REQUIREMENTS_LIST = (10)
  194. End Enum
  195.  
  196. Private m_hClassKey As Long
  197. Private m_sSectionKey As String
  198. Private m_sValueKey As String
  199. Private m_vValue As Variant
  200. Private m_sSetValue As String
  201. Private m_vDefault As Variant
  202. Private m_eValueType As ERegistryValueTypes
  203.  
  204. Public Property Get KeyExists() As Boolean
  205. Dim hKey As Long
  206.   If RegOpenKeyEx(m_hClassKey, m_sSectionKey, 0, 1, hKey) = ERROR_SUCCESS Then
  207.       KeyExists = True
  208.       RegCloseKey hKey
  209.   Else
  210.       KeyExists = False
  211.   End If
  212. End Property
  213.  
  214. Public Function CreateKey() As Boolean
  215. Dim tSA As SECURITY_ATTRIBUTES
  216. Dim hKey As Long
  217. Dim lCreate As Long
  218. Dim e As Long
  219.  
  220.   'Open or Create the key
  221.   e = RegCreateKeyEx(m_hClassKey, m_sSectionKey, 0, "", REG_OPTION_NON_VOLATILE, _
  222.                KEY_ALL_ACCESS, tSA, hKey, lCreate)
  223.   If e Then
  224.       Err.Raise 26001, App.EXEName & ".cRegistry", "Failed to create registry Key: '" & m_sSectionKey
  225.   Else
  226.       CreateKey = (e = ERROR_SUCCESS)
  227.       'Close the key
  228.       RegCloseKey hKey
  229.   End If
  230. End Function
  231.  
  232. Public Function DeleteKey() As Boolean
  233. Dim e As Long
  234.   e = RegDeleteKey(m_hClassKey, m_sSectionKey)
  235.   If e Then
  236.       Err.Raise 26001, App.EXEName & ".cRegistry", "Failed to delete registry Key: '" & m_hClassKey & "',Section: '" & m_sSectionKey
  237.   Else
  238.       DeleteKey = (e = ERROR_SUCCESS)
  239.   End If
  240.     
  241. End Function
  242.  
  243. Public Function DeleteValue() As Boolean
  244. Dim e As Long
  245. Dim hKey As Long
  246.  
  247.     e = RegOpenKeyEx(m_hClassKey, m_sSectionKey, 0, KEY_ALL_ACCESS, hKey)
  248.     If e Then
  249.         Err.Raise 26001, App.EXEName & ".cRegistry", "Failed to open key '" & m_hClassKey & "',Section: '" & m_sSectionKey & "' for delete access"
  250.     Else
  251.         e = RegDeleteValue(hKey, m_sValueKey)
  252.         If e Then
  253.             Err.Raise 26001, App.EXEName & ".cRegistry", "Failed to delete registry Key: '" & m_hClassKey & "',Section: '" & m_sSectionKey & "',Key: '" & m_sValueKey
  254.         Else
  255.             DeleteValue = (e = ERROR_SUCCESS)
  256.         End If
  257.     End If
  258.  
  259. End Function
  260.  
  261. Public Property Get Value() As Variant
  262. Dim vValue As Variant
  263. Dim cData As Long, sData As String, ordType As Long, e As Long
  264. Dim hKey As Long
  265.  
  266.     e = RegOpenKeyEx(m_hClassKey, m_sSectionKey, 0, KEY_QUERY_VALUE, hKey)
  267.     'ApiRaiseIfáe
  268.  
  269.     e = RegQueryValueExLong(hKey, m_sValueKey, 0&, ordType, 0&, cData)
  270.     If e And e <> ERROR_MORE_DATA Then
  271.         Value = m_vDefault
  272.         Exit Property
  273.     End If
  274.     
  275.     m_eValueType = ordType
  276.     Select Case ordType
  277.     Case REG_DWORD, REG_DWORD_LITTLE_ENDIAN
  278.         Dim iData As Long
  279.         e = RegQueryValueExLong(hKey, m_sValueKey, 0&, _
  280.                                ordType, iData, cData)
  281.         vValue = CLng(iData)
  282.         
  283.     Case REG_DWORD_BIG_ENDIAN  ' Unlikely, but you never know
  284.         Dim dwData As Long
  285.         e = RegQueryValueExLong(hKey, m_sValueKey, 0&, _
  286.                                ordType, dwData, cData)
  287.         vValue = SwapEndian(dwData)
  288.         
  289.     Case REG_SZ, REG_MULTI_SZ ' Same thing to Visual Basic
  290.         sData = String$(cData - 1, 0)
  291.         e = RegQueryValueExStr(hKey, m_sValueKey, 0&, _
  292.                                ordType, sData, cData)
  293.         vValue = sData
  294.         
  295.     Case REG_EXPAND_SZ
  296.         sData = String$(cData - 1, 0)
  297.         e = RegQueryValueExStr(hKey, m_sValueKey, 0&, _
  298.                                ordType, sData, cData)
  299.         vValue = ExpandEnvStr(sData)
  300.         
  301.     ' Catch REG_BINARY and anything else
  302.     Case Else
  303.         Dim abData() As Byte
  304.         ReDim abData(cData)
  305.         e = RegQueryValueExByte(hKey, m_sValueKey, 0&, _
  306.                                 ordType, abData(0), cData)
  307.         vValue = abData
  308.         
  309.     End Select
  310.     Value = vValue
  311.     
  312. End Property
  313.  
  314. Public Property Let Value(ByVal vValue As Variant)
  315. Dim ordType As Long
  316. Dim c As Long
  317. Dim hKey As Long
  318. Dim e As Long
  319. Dim lCreate As Long
  320. Dim tSA As SECURITY_ATTRIBUTES
  321.  
  322.     'Open or Create the key
  323.     e = RegCreateKeyEx(m_hClassKey, m_sSectionKey, 0, "", REG_OPTION_NON_VOLATILE, _
  324.                  KEY_ALL_ACCESS, tSA, hKey, lCreate)
  325.     
  326.     If e Then
  327.         Err.Raise 26001, App.EXEName & ".cRegistry", "Failed to set registry value Key: '" & m_hClassKey & "',Section: '" & m_sSectionKey & "',Key: '" & m_sValueKey & "' to value: '" & m_vValue & "'"
  328.     Else
  329.  
  330.         Select Case m_eValueType
  331.         Case REG_BINARY
  332.             If (VarType(vValue) = vbArray + vbByte) Then
  333.                 Dim ab() As Byte
  334.                 ab = vValue
  335.                 ordType = REG_BINARY
  336.                 c = UBound(ab) - LBound(ab) - 1
  337.                 e = RegSetValueExByte(hKey, m_sValueKey, 0&, ordType, ab(0), c)
  338.             Else
  339.                 Err.Raise 26001
  340.             End If
  341.         Case REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_DWORD_LITTLE_ENDIAN
  342.             If (VarType(vValue) = vbInteger) Or (VarType(vValue) = vbLong) Then
  343.                 Dim i As Long
  344.                 i = vValue
  345.                 ordType = REG_DWORD
  346.                 e = RegSetValueExLong(hKey, m_sValueKey, 0&, ordType, i, 4)
  347.             End If
  348.         Case REG_SZ, REG_EXPAND_SZ
  349.             Dim s As String, iPos As Long
  350.             s = vValue
  351.             ordType = REG_SZ
  352.             ' Assume anything with two non-adjacent percents is expanded string
  353.             iPos = InStr(s, "%")
  354.             If iPos Then
  355.                 If InStr(iPos + 2, s, "%") Then ordType = REG_EXPAND_SZ
  356.             End If
  357.             c = Len(s) + 1
  358.             e = RegSetValueExStr(hKey, m_sValueKey, 0&, ordType, s, c)
  359.             
  360.         ' User should convert to a compatible type before calling
  361.         Case Else
  362.             e = ERROR_INVALID_DATA
  363.             
  364.         End Select
  365.         
  366.         If Not e Then
  367.             m_vValue = vValue
  368.         Else
  369.             Err.Raise vbObjectError + 1048 + 26001, App.EXEName & ".cRegistry", "Failed to set registry value Key: '" & m_hClassKey & "',Section: '" & m_sSectionKey & "',Key: '" & m_sValueKey & "' to value: '" & m_vValue & "'"
  370.         End If
  371.         
  372.         'Close the key
  373.         RegCloseKey hKey
  374.     
  375.     End If
  376.     
  377. End Property
  378.  
  379. Public Function EnumerateValues(ByRef sKeyNames() As String, _
  380.                                 ByRef iKeyCount As Long) As Boolean
  381. Dim lResult As Long
  382. Dim hKey As Long
  383. Dim sName As String
  384. Dim lNameSize As Long
  385. Dim sData As String
  386. Dim lIndex As Long
  387. Dim cJunk As Long
  388. Dim cNameMax As Long
  389. Dim ft As Currency
  390.    
  391.    ' Log "EnterEnumerateValues"
  392.  
  393.    iKeyCount = 0
  394.    Erase sKeyNames()
  395.     
  396.    lIndex = 0
  397.    lResult = RegOpenKeyEx(m_hClassKey, m_sSectionKey, 0, KEY_QUERY_VALUE, hKey)
  398.    If (lResult = ERROR_SUCCESS) Then
  399.       ' Log "OpenedKey:" & m_hClassKey & "," & m_sSectionKey
  400.       lResult = RegQueryInfoKey(hKey, "", cJunk, 0, _
  401.                                cJunk, cJunk, cJunk, cJunk, _
  402.                                cNameMax, cJunk, cJunk, ft)
  403.        Do While lResult = ERROR_SUCCESS
  404.    
  405.            'Set buffer space
  406.            lNameSize = cNameMax + 1
  407.            sName = String$(lNameSize, 0)
  408.            If (lNameSize = 0) Then lNameSize = 1
  409.            
  410.            ' Log "Requesting Next Value"
  411.          
  412.            'Get value name:
  413.            lResult = RegEnumValue(hKey, lIndex, sName, lNameSize, _
  414.                                   0&, 0&, 0&, 0&)
  415.            ' Log "RegEnumValue returned:" & lResult
  416.            If (lResult = ERROR_SUCCESS) Then
  417.        
  418.                 ' Although in theory you can also retrieve the actual
  419.                 ' value and type here, I found it always (ultimately) resulted in
  420.                 ' a GPF, on Win95 and NT.  Why?  Can anyone help?
  421.        
  422.                sName = Left$(sName, lNameSize)
  423.                ' Log "Enumerated value:" & sName
  424.                  
  425.                iKeyCount = iKeyCount + 1
  426.                ReDim Preserve sKeyNames(1 To iKeyCount) As String
  427.                sKeyNames(iKeyCount) = sName
  428.            End If
  429.            lIndex = lIndex + 1
  430.        Loop
  431.    End If
  432.    If (hKey <> 0) Then
  433.       RegCloseKey hKey
  434.    End If
  435.  
  436.    ' Log "Exit Enumerate Values"
  437.    EnumerateValues = True
  438.    Exit Function
  439.    
  440. EnumerateValuesError:
  441.    If (hKey <> 0) Then
  442.       RegCloseKey hKey
  443.    End If
  444.    Err.Raise vbObjectError + 1048 + 26003, App.EXEName & ".cRegistry", Err.Description
  445.    Exit Function
  446.  
  447. End Function
  448.  
  449. Public Function EnumerateSections(ByRef sSect() As String, _
  450.                                   ByRef iSectCount As Long) As Boolean
  451. Dim lResult As Long
  452. Dim hKey As Long
  453. Dim dwReserved As Long
  454. Dim szBuffer As String
  455. Dim lBuffSize As Long
  456. Dim lIndex As Long
  457. Dim lType As Long
  458. Dim sCompKey As String
  459. Dim iPos As Long
  460.  
  461. On Error GoTo EnumerateSectionsError
  462.  
  463.    iSectCount = 0
  464.    Erase sSect
  465. '
  466.    lIndex = 0
  467.  
  468.    lResult = RegOpenKeyEx(m_hClassKey, m_sSectionKey, 0, KEY_ENUMERATE_SUB_KEYS, hKey)
  469.    Do While lResult = ERROR_SUCCESS
  470.        'Set buffer space
  471.        szBuffer = String$(255, 0)
  472.        lBuffSize = Len(szBuffer)
  473.       
  474.       'Get next value
  475.        lResult = RegEnumKey(hKey, lIndex, szBuffer, lBuffSize)
  476.                              
  477.        If (lResult = ERROR_SUCCESS) Then
  478.            iSectCount = iSectCount + 1
  479.            ReDim Preserve sSect(1 To iSectCount) As String
  480.            iPos = InStr(szBuffer, Chr$(0))
  481.            If (iPos > 0) Then
  482.               sSect(iSectCount) = Left(szBuffer, iPos - 1)
  483.            Else
  484.               sSect(iSectCount) = Left(szBuffer, lBuffSize)
  485.            End If
  486.        End If
  487.        
  488.        lIndex = lIndex + 1
  489.    Loop
  490.    If (hKey <> 0) Then
  491.       RegCloseKey hKey
  492.    End If
  493.    EnumerateSections = True
  494.    Exit Function
  495.  
  496. EnumerateSectionsError:
  497.    If (hKey <> 0) Then
  498.       RegCloseKey hKey
  499.    End If
  500.    Err.Raise vbObjectError + 1048 + 26002, App.EXEName & ".cRegistry", Err.Description
  501.    Exit Function
  502. End Function
  503.  
  504. Public Sub CreateEXEAssociation( _
  505.         ByVal sExePath As String, _
  506.         ByVal sClassName As String, _
  507.         ByVal sClassDescription As String, _
  508.         ByVal sAssociation As String, _
  509.         Optional ByVal lDefaultIconIndex As Long = -1 _
  510.     )
  511.     ClassKey = HKEY_CLASSES_ROOT
  512.     SectionKey = "." & sAssociation
  513.     ValueKey = ""
  514.     Value = sClassName
  515.     SectionKey = "." & sAssociation & "\shell\open\command"
  516.     ValueKey = ""
  517.     Value = sExePath & " ""%1"""
  518.     
  519.     SectionKey = sClassName
  520.     ValueKey = ""
  521.     Value = sClassDescription
  522.     SectionKey = sClassName & "\shell\open\command"
  523.     ValueKey = sExePath & " ""%1"""
  524.     If lDefaultIconIndex > -1 Then
  525.         SectionKey = sClassName & "\DefaultIcon"
  526.         ValueKey = ""
  527.         Value = sExePath & "," & CStr(lDefaultIconIndex)
  528.     End If
  529.     
  530. End Sub
  531.  
  532. Public Property Get ValueType() As ERegistryValueTypes
  533.     ValueType = m_eValueType
  534. End Property
  535.  
  536. Public Property Let ValueType(ByVal eValueType As ERegistryValueTypes)
  537.     m_eValueType = eValueType
  538. End Property
  539.  
  540. Public Property Get ClassKey() As ERegistryClassConstants
  541.     ClassKey = m_hClassKey
  542. End Property
  543.  
  544. Public Property Let ClassKey( _
  545.         ByVal eKey As ERegistryClassConstants _
  546.     )
  547.     m_hClassKey = eKey
  548. End Property
  549.  
  550. Public Property Get SectionKey() As String
  551.     SectionKey = m_sSectionKey
  552. End Property
  553.  
  554. Public Property Let SectionKey( _
  555.         ByVal sSectionKey As String _
  556.     )
  557.     m_sSectionKey = sSectionKey
  558. End Property
  559.  
  560. Public Property Get ValueKey() As String
  561.     ValueKey = m_sValueKey
  562. End Property
  563.  
  564. Public Property Let ValueKey( _
  565.         ByVal sValueKey As String _
  566.     )
  567.     m_sValueKey = sValueKey
  568. End Property
  569.  
  570. Public Property Get Default() As Variant
  571.     Default = m_vDefault
  572. End Property
  573.  
  574. Public Property Let Default( _
  575.         ByVal vDefault As Variant _
  576.     )
  577.     m_vDefault = vDefault
  578. End Property
  579.  
  580. Private Function SwapEndian(ByVal dw As Long) As Long
  581.     CopyMemory ByVal VarPtr(SwapEndian) + 3, dw, 1
  582.     CopyMemory ByVal VarPtr(SwapEndian) + 2, ByVal VarPtr(dw) + 1, 1
  583.     CopyMemory ByVal VarPtr(SwapEndian) + 1, ByVal VarPtr(dw) + 2, 1
  584.     CopyMemory SwapEndian, ByVal VarPtr(dw) + 3, 1
  585. End Function
  586.  
  587. Private Function ExpandEnvStr(sData As String) As String
  588.     Dim c As Long, s As String
  589.     ' Get the length
  590.     s = "" ' Needed to get around Windows 95 limitation
  591.     c = ExpandEnvironmentStrings(sData, s, c)
  592.     ' Expand the string
  593.     s = String$(c - 1, 0)
  594.     c = ExpandEnvironmentStrings(sData, s, c)
  595.     ExpandEnvStr = s
  596. End Function
  597.