vorpal wrote in vbdev

RegOpenKeyEx problems...

Hi all,

I'm trying to open a Registry key using RegOpenKeyEx, but I'm having problems. The function constantly returns error 87, which is "Invalid Parameter". All my parameters seem fine, so I have no clue what's going on.

What's even stranger is that if I go into regedit and click on the registry keys that I need and then rerun my program, it works fine and I get no errors.

Any clue? I'm ripping out my hair here.


If VersionExists("SOFTWARE\\Financial Models\\FMCSylvan", "6.0") Then
    bClient = True
End If
If VersionExists("SOFTWARE\\Financial Models\\FMCSylvan Application Server", "6.0") Then
    bAppServer = True
End If
If VersionExists("SOFTWARE\\Financial Models\\FMCSylvan Database Server", "6.0") Then
    bDatabaseServer = True
End If


Private Function VersionExists(SubKey As String, Version As String) As Boolean
    Dim lRetVal As Long
    Dim hKey As Long
    Dim lNumKeys As Long
    Dim lSubkeyNameLen As Long
    Dim dwIndex As Long
    Dim sBuffer As String
    Dim lBuffer As Long
    Dim ft As FILETIME
    
    ' Attempt to open the key
    ' ******* ERROR OCCURS HERE ******
    lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, KEY_ENUMERATE_SUB_KEYS, hKey)
    MsgBox (str(lRetVal))
    
    If lRetVal <> ERROR_SUCCESS Then
        VersionExists = False
        Exit Function
    End If
    
    ' This point is never reached...
...