PDA

Click to See Complete Forum and Search --> : Won't you Please, please help me...??


barrk
Dec 6th, 2000, 05:33 PM
I have already searched on regenumkeyex in the forum and seen examples from msdn regarding how to use the registry api to save and retrieve settings and I'm still stuck.

What I'm trying to do is use this API in an Active-x control. It works fine in the VB environment but when I deploy it, it no longer works.

Could someone please give me an example...not just the code from msdn...of how to do this? I think the problem is related to the lpreserved parameter. It tells you that it is reserved and must be null but when I pass null to it..it tells me "invalid use of null"

Yikes!

************************************

I have found a temporary fix for this now but would really like a long term answer if anyone has any suggestions.

Thanks,
Katie

[Edited by barrk on 12-06-2000 at 06:49 PM]

Nitro
Dec 6th, 2000, 07:34 PM
Hello Barrk,

I don't know if this is the same, but you might want to check it out.

http://www.vbapi.com/ref/r/regenumkeyex.html

barrk
Dec 7th, 2000, 09:38 AM
Thanks Dr. Nitro...I'll check it out and let you know!

Wak
Dec 7th, 2000, 09:07 PM
This should work

Option Explicit

'You must open the key before enuming it
Private Declare Function RegOpenKey _
Lib "advapi32.dll" Alias "RegOpenKeyA" ( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long _
) As Long

'Enum function for currently opened key
Private Declare Function RegEnumKeyEx _
Lib "advapi32.dll" Alias "RegEnumKeyExA" ( _
ByVal hKey As Long, _
ByVal dwIndex As Long, _
ByVal lpName As String, _
lpcbName As Long, _
ByVal lpReserved As Long, _
ByVal lpClass As String, _
lpcbClass As Long, _
lpftLastWriteTime As FILETIME _
) As Long

'Type Filetime for enum function
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Dim lastwrite As FILETIME

'Assuming you are writing to the CURRENT_USER KEY
constant HKEY_CURRENT_USER = &H80000001

'Handle for opened key
Dim lHandle As Long

Private Sub Form_Load()
Dim retVal As Integer
Dim lpName As String
Dim lpcbName As String
Dim lpClass As String
Dim lpcbClass As String
'Must have sufficent space, can set to whatever
lpName = Space$(255)
'Must be the same size as lpName explain after
lpcbName = Space$(255)
'Also must have sufficient space
lpClass = Space$(255)
'Must be the same as lpClass
lpcbClass = Space$(255)


retVal = RegOpenKey(HKEY_CURRENT_USER, "\Software", lHandle)

'Return 0 if successfull anything else means error
If retVal <> 0 Then Exit Sub

retVal = RegEnumKeyEx(lHandle, 1, lpName, lpcbName, ByVal 0, lpClass, lpcbClass, lastwrite)

'Returns 0 if successfull
If retVal <> 0 Then Exit Sub

Do Until retVal <> 0
retVal = RegEnumKeyEx(key_current_user, 1, lpName, lpcbName, ByVal 0, lpClass, lpcbClass, lastwrite)
MsgBox lpName
Loop

'Explanation of variables
'dwIndex: The index of the subkey that is wished to be received
'lpName: The name of the subkey whose info is being received
'lpcbName: The len or size of lpName
'lpReserved: Because it's a C++ variable must be ByVal, must be set to 0
'lpClass: String which revieves Subkey's class
'lpcbClass: len or size of lpClass
'writetime: time and date on which the subkey was last written to

'Key must be closed using regCloseKey after use.
End Sub

:)Reply if it doesn't work!:)



[Edited by Wak on 12-08-2000 at 07:03 PM]

Nitro
Dec 8th, 2000, 03:42 AM
Wak!

I may be wrong, but I think you need to put an incrementation in your RegEnumKeyEx within your "Do Loop".



Option Explicit

'Private 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
'Private Const KEY_ENUMERATE_SUB_KEYS = &H8
' lng_Return = RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ENUMERATE_SUB_KEYS, lng_Handle)

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Const HKEY_CURRENT_USER = &H80000001

Sub Main()
'PURPOSE: Open the registry key.
Dim lng_Return As Long
Dim lng_Handle As Long ' handle
lng_Return = RegOpenKey(HKEY_CURRENT_USER, "Software", lng_Handle)

'PURPOSE: Make sure the key was opened successfully.
If lng_Return <> 0 Then
Debug.Print "Registry key could not be opened -- aborting."
End
End If

'PURPOSE: List through each possible subkey.
Dim f_LastWrite As FILETIME ' receives last-write-to time
Dim str_KeyName As String
Dim lng_KeyLength As Long
Dim str_Classname As String
Dim lng_ClassLength As Long
Dim int_X As Long

Do Until lng_Return <> 0
str_KeyName = Space(255)
lng_KeyLength = Len(str_KeyName)

str_Classname = Space(255)
lng_ClassLength = Len(str_Classname)

'PURPOSE: Get information about the next subkey
lng_Return = RegEnumKeyEx(lng_Handle, int_X, str_KeyName, lng_KeyLength, ByVal 0, str_Classname, lng_ClassLength, f_LastWrite)

If lng_Return = 0 Then ' only display info if another subkey was found
str_KeyName = Left(str_KeyName, lng_KeyLength) ' trim off the excess space
Debug.Print int_X & ". HKEY_CURRENT_USER\Software\"; str_KeyName

str_Classname = Left(str_Classname, lng_ClassLength)
Debug.Print "CLASS: "; str_Classname

Debug.Print ""
End If

int_X = int_X + 1
Loop

'PURPOSE: Close the registry key
Call RegCloseKey(lng_Handle)
End Sub


Have a good day! :)

barrk
Dec 8th, 2000, 11:50 AM
Thanks for all the help! I think we've got it covered now. We much appreciate everything you guys did to help!