PDA

Click to See Complete Forum and Search --> : help needed in RegQueryValueEx


manishmenghani
Apr 26th, 2001, 04:22 AM
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

parksie
Apr 27th, 2001, 12:26 PM
Are you sure they're all REG_SZ values?

manishmenghani
Apr 30th, 2001, 12:14 AM
Yes all of them are REG_SZ

MerrionComputin
Apr 30th, 2001, 06:15 AM
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

manishmenghani
Apr 30th, 2001, 06:25 AM
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