Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_SET_VALUE = &H2
Public Const SYNCHRONIZE = &H100000
Public Const REG_DWORD = 4 ' 32-bit number
Public Const REG_SZ = 1 ' Unicode nul terminated string
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Sub Main()
Dim hKey
Dim openRet, Ret
Dim dtRet As String, dtLen As Long
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Visual Basic\5.0
openRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Visual Basic\5.0", _
0&, KEY_ALL_ACCESS, hKey)
If openRet = 2 Then
MsgBox "SUB-KEY Not Found !!!"
Exit Sub
End If
dtLen = 255
dtRet = Space(dtLen)
'---------------------------
'*** ERROR IN NEXT LINE ***
'---------------------------
Ret = RegQueryValueEx(hKey, "InstallDir", 0&, REG_SZ, dtRet, dtLen)
MsgBox "OpenReturn=" & openRet & Space(20) & _
"hKey=" & hKey & vbCrLf & _
"QueryReturn=" & Ret & Space(20) & _
"QueryValue=" & RTrim(dtRet)
Ret = RegCloseKey(hKey)
End Sub