Results 1 to 5 of 5

Thread: help needed in RegQueryValueEx

  1. #1
    manishmenghani
    Guest

    help needed in RegQueryValueEx

    Hey Guys ,

    I m stucked in a problem while using RegQueryValueEx API . the problem is like , In My registry in a key there are 5 data values . I want to retrieve these values . I m calling the regQueryValueEx 5 times to get the value from the key .

    But the problem is that sometimes it gives me successful results in 3 key , sometimes in 4 key . However I ve values in all the keys
    Is there a bug in RegQueryValueEx or if u know any alternate of it then pls help me .

    my code goes ike this :

    lRetVal = RegQueryValueEx(hKey, COMM_PORT, 0, lType, ByVal sTemp, sLength)
    If lRetVal = ERROR_SUCCESS Then
    sCommPort = Left(sTemp, sLength - 1)
    End If

    lRetVal = RegQueryValueEx(hKey, BAUD_RATE, 0, lType, ByVal sTemp, sLength)
    If lRetVal = ERROR_SUCCESS Then
    sBaudRate = Left(sTemp, sLength - 1)
    End If

    lRetVal = RegQueryValueEx(hKey, DATA_BITS, 0, lType, ByVal sTemp, sLength)
    If lRetVal = ERROR_SUCCESS Then
    sDataBits = Left(sTemp, sLength - 1)
    End If

    lRetVal = RegQueryValueEx(hKey, PARITY_BITS, 0&, lType, ByVal sTemp, sLength)
    If lRetVal = ERROR_SUCCESS Then
    sParity = Left(sTemp, sLength - 1)
    End If

    lRetVal = RegQueryValueEx(hKey, STOP_BITS, 0, lType, ByVal sTemp, sLength)
    If lRetVal = ERROR_SUCCESS Then
    sStopBits = Left(sTemp, sLength - 1)
    End If

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Are you sure they're all REG_SZ values?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    manishmenghani
    Guest
    Yes all of them are REG_SZ

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Lightbulb

    I have the following for my declaration:

    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long


    I have noticed that when this call fails it doesn't set the App.LastDllError but rather returns the error. A return of 254 means that your lpData string value was not initialised long enough.
    What is probably happening here is that it works OK so long as the 1st string is longer than the second is longer than the third etc. but because you are not reinitialissing the string buffer between calls it doesn't work if the above is not true.

    Try adding:
    sLength = 2000
    sTemp = String$(slength, 0)

    between each call.

    HTH,
    Duncan

  5. #5
    manishmenghani
    Guest
    yeah , thats works
    Thanku very much.

    However I had made it work by changing its position , but I was not getting why they were working fine like that

    Now its solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width