Obviously I'm missing something fundamental here. I get a successful result (0 on CallResult) along with the correct value type (KeyType = 1) and buffer size (KeySize = 35). I just never get the string value - which is what I want. It always comes back empty (KeyVal = "". I've gone through several Microsoft examples and I can't figure out what I'm doing wrong. Help!
My test code is to supposed to bring back the path of the IE4 setup (non-critical for safety). I've tried a few other keys as well and can't get them to work either. The code goes like this
Module 1:
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
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Attached to a command button:
Private Sub Command1_Click()
Dim CallResult As Long
Dim hKey As Long
Dim KeyType As Long
Dim KeyVal As String
Dim KeySize As Long
CallResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\IE4\Setup", 0, &H1, hKey)
CallResult = RegQueryValueEx(hKey, "Path", 0&, KeyType, ByVal KeyVal, KeySize)
CallResult = RegCloseKey(hKey)
End Sub
My test code is to supposed to bring back the path of the IE4 setup (non-critical for safety). I've tried a few other keys as well and can't get them to work either. The code goes like this
Module 1:
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
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Attached to a command button:
Private Sub Command1_Click()
Dim CallResult As Long
Dim hKey As Long
Dim KeyType As Long
Dim KeyVal As String
Dim KeySize As Long
CallResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\IE4\Setup", 0, &H1, hKey)
CallResult = RegQueryValueEx(hKey, "Path", 0&, KeyType, ByVal KeyVal, KeySize)
CallResult = RegCloseKey(hKey)
End Sub