
Reading Registry in a 16-bit program
I am trying to retrieve a value from the registry in VB4-16 using
RegQueryValue and the following code. I always get a return value of 2
from the RegQueryValue call. I know the key exists and has a value in it.
I am not sure about my declarations or how I have dimmed the variable Ans
or AnsSize. I am having a lot of trouble finding help on the use of the
16-bit functions.
Private Declare Function RegQueryValue Lib "shell.dll" (ByVal hKey As Long,
ByRef lpSubKey As String, ByRef lpValue As String, ByRef lpcbValue As Long)
As Long
Private Declare Function RegOpenKey Lib "shell.dll" (ByVal hKey As Long,
ByVal lpSubKey As String, ByRef phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "shell.dll" (ByVal hKey As Long)
As Long
Dim hKey As Long
Dim RetVal As Long
Dim Ans As String * 255
Dim AnsSize As Long
Dim SubKey As String
Const HKEY_CURRENT_USER = &H80000001
SubKey = "Software\Microsoft\Windows Messaging Subsystem\Profiles"
AnsSize = Len(Ans)
RetVal = RegOpenKey(HKEY_CURRENT_USER, SubKey, hKey)
If RetVal <> 0 Then
MsgBox "can't find key"
End
End If
SubKey = "DefaultProfile"
RetVal = RegQueryValue(hKey, SubKey, Ans, AnsSize)
If RetVal <> 0 Then
MsgBox "can't find value"
End
End If
Label1.Caption = Ans
Label1.Refresh
RetVal = RegCloseKey(hKey)
Thanks in advance
Jeff DeRouse