Problem using APIs in VB6 on a Vista machine Beta2 August

Discussion in 'Windows Vista General Discussion' started by Garry Grolman, Sep 18, 2006.

  1. I use the following code:

    Public Function RegGetKeyValueP(strKey As String, strSubKey As String) As

    Dim lngSubkeyHandle As Long
    Dim lngStatus As Long
    Dim lngValueType As Long
    Dim lngValueSize As Long

    'Use the GetSubkeyHandle function to determine the handle of the
    subkey given in txtSectionName.
    lngSubkeyHandle = GetSubkeyHandle(strKey)
    If lngSubkeyHandle = -1 Then
    'Subkey could not be located.
    RegGetKeyValueP = ""
    Exit Function
    End If

    'Use the RegQueryValueEx API function to retrieve
    ' the value of the key given in txtKeyName.
    lngValueType = REG_SZ
    lngValueSize = 256
    gstrKeyValue = Space(lngValueSize)
    lngStatus = RegQueryValueEx(lngSubkeyHandle, Trim$(strSubKey), 0,
    lngValueType, ByVal gstrKeyValue, lngValueSize)
    If lngStatus <> 0 Then
    'Key could not be located.
    RegGetKeyValueP = ""
    If lngValueSize > 0 Then
    RegGetKeyValueP = Left$(gstrKeyValue, lngValueSize -
    1) 'minus 1 to remove the Null terminator
    RegGetKeyValueP = ""
    End If
    End If

    ' Close the open subkey with the CloseSubKey function.
    lngStatus = CloseSubkey(lngSubkeyHandle)

    End Function

    to get a registry value. I have been using it for six years thru win 98 to
    win XP. The code was copied from a site that I dont remember.
    The line RegGetKeyValueP = Left$(gstrKeyValue, lngValueSize - 1) 'minus
    1 to remove the Null terminator
    does not return the correct value in Vista as it used to in preceeding
    operating systems. If the key value is "894468" the code returns "89446". I
    can solve it by using RegGetKeyValueP = Trim$(gstrKeyValue) but this seems
    problematic as who knows where else dealing with a NULL character in VB6
    will cause a problem.

    The whole caboodle and many other registry functions are wrapped up in a vb6

    Does anyone have anything to explain this abberation or have a comment that
    will give me more confidence to use the $Trim vb function.

    Thanking you in advance.

    Garry Grolman, Sep 18, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.