I think you are missing a couple of items dealing with the return type.
You can try this module or paste the missing parts into your form. You
will also just use msgbox's for your error coding(remove the enumerated
error constants).
'-- Module : VbRegMod
'-- Module File : VbRegMod.bas
'-- Project : Project1
'-- Project File: Project1.vbp
'-- Parameters :
'-- RootKey : The Root Key To Open, EG: HKEY_CURRENT_USER
'-- KeyName : The Key Name To Open
'-- : Example: MySettings\Settings
'-- ValueName : The Value Name To Query
'-------------------------------------------------------------
'
Public Function VbRegQueryValue _
(RootKey As Long, KeyName As String, ValueName As String) As
Variant
Dim lRtn As Long '-- API Return Code
Dim hKey As Long '-- Handle Of Open Key
Dim lCdata As Long '-- The Data
Dim lValue As Long '-- Long (DWORD) Value
Dim sValue As String '-- String Value
Dim lRtype As Long '-- Type Returned String Or DWORD
'-- Open The Registry Key.
lRtn = RegOpenKeyEx(RootKey, KeyName, 0&, KEY_ALL_ACCESS, hKey)
'-- Check For An Error.
If lRtn <> ERROR_SUCCESS Then
'MsgBox OpenErr
Err.Raise ieCantOpenRegKey
RegCloseKey (hKey)
Exit Function
End If
'-- Query Registry Key For Value Type.
lRtn = RegQueryValueExNULL(hKey, ValueName, 0&, lRtype, 0&, lCdata)
'-- Check For An Error.
If lRtn <> ERROR_SUCCESS Then
'MsgBox QueryErr
Err.Raise ieCantQueryRegKey
RegCloseKey (hKey)
Exit Function
End If
'-- Get The Key Value By Type.
Select Case lRtype
Case 1 '-- REG_SZ (String)
sValue = String(lCdata, 0)
'-- Get Registry String Value.
lRtn = RegQueryValueExString(hKey, ValueName, 0&, lRtype, sValue,
lCdata)
'-- Check For Error.
If lRtn = ERROR_SUCCESS Then
VbRegQueryValue = sValue
Else
VbRegQueryValue = Empty
End If
Case 4 '-- REG_DWORD
'-- Get Registry Long (DWORD) Value.
lRtn = RegQueryValueExLong(hKey, ValueName, 0&, lRtype, lValue,
lCdata)
'-- Check For Error.
If lRtn = ERROR_SUCCESS Then
VbRegQueryValue = lValue
Else
VbRegQueryValue = Empty
End If
End Select
'-- Close The Registry Key.
RegCloseKey (hKey)
End Function
-----Original Message-----
From: professional vb [SMTP:pro_vb@p...]
Sent: Thursday, February 08, 2001 3:21 PM
To: professional vb
Subject: [pro_vb] Registry query value
I am able to open a registry key but not value to obtain the from the
registry name. I am getting a return code of 234. I am not sure what it
means. I am able to creat a key if the means anything. I am using the
following code
Private Sub Form_Load()
Dim rootkey As Long
Dim strRegistryValue As String
Dim strRegistryName As String
Dim rdtValuePassed As RegistryDataTypes
rdtValuePassed = REG_LONG
Dim lngdisposition As Long
Dim lngregsize As Long
Dim securityattributes As SECURITY_ATTRIBUTES
Dim ft As FILETIME
controlkey = "SOFTWARE\APPLICATIONS\PRAXAIR\FILLZONE"
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, controlkey, 0&, KEY_READ, rootkey)
If res <> 0 Then
MsgBox "Unable to open registry key: " ' & geterrorstring(res)
Exit Sub
Else
'MsgBox "Key opened successfully"
Debug.Print "Key opened successfully!!! " & rootkey & vbCrLf
End If
controlkey = "SOFTWARE\APPLICATIONS\PRAXAIR\FILLZONE"
rootkey = 0
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, controlkey, 0&, KEY_READ, rootkey)
strRegistryName = "NodeType"
strRegistryValue = ""
lngregsize = 0 'set to 0
cause no value in strRegistryValue
rdtValuePassed = 1
res = RegQueryValueEx(rootkey, strRegistryName, 0, rdtValuePassed,
strRegistryValue, lngregsize)
res = RegCloseKey(rootkey)
end sub
________________________
note i did not include the api and constant declares since it would make
the
message very long. I you want to see the rest just let me know if you
think
you know what i need to do to correct this error.
any ideas? I think the problem is access rights and do not know what to
do
to correct this problem. I am using read access for the query.
Thanks in advance,
Fredrick J. Krantz