Function RegGetValue$(MainKey&, SubKey$, value$)
' MainKey must be one of the Publicly declared HKEY constants.
Dim sKeyType& 'returns the key type. This function expects REG_SZ or REG_DWORD
Dim ret& 'returned by registry functions, should be 0&
Dim lpHKey& 'return handle to opened key
Dim lpcbData& 'length of data in returned string
Dim ReturnedString$ 'returned string value Dim fTempDbl!
If MainKey >= &H80000000 And MainKey <= &H80000006 Then ' Open key
ret = RegOpenKeyExA(MainKey, SubKey, 0&, Key_Read, lpHKey)
If ret <> ERROR_SUCCESS Then RegGetValue = ""
Exit Function 'No key open, so leave
End If
' Set up buffer for data to be returned in.
' Adjust next value for larger buffers. lpcbData = 255
ReturnedString = Space$(lpcbData) ' Read key
ret& = RegQueryValueExA(lpHKey, value, ByVal 0&, _
sKeyType, ReturnedString, lpcbData)
If ret <> ERROR_SUCCESS Then
RegGetValue = "" 'Key still open, so finish up
Else
If sKeyType = REG_DWORD Then
fTempDbl = Asc(Mid$(ReturnedString, 1, 1)) + _
&H100& * Asc(Mid$(ReturnedString, 2, 1)) + _
&H10000 * Asc(Mid$(ReturnedString, 3, 1)) + _
&H1000000 * CDbl(Asc(Mid$(ReturnedString, 4, 1)))
RegGetValue = Format$(fTempDbl, "000")
Else
RegGetValue = Left$(ReturnedString, lpcbData - 1)
End If
End If ' Always close opened keys. ret = RegCloseKey(lpHKey)
End If
End Function