|
-
Apr 26th, 2001, 04:22 AM
#1
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
-
Apr 27th, 2001, 12:26 PM
#2
Monday Morning Lunatic
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
-
Apr 30th, 2001, 12:14 AM
#3
Yes all of them are REG_SZ
-
Apr 30th, 2001, 06:15 AM
#4
Frenzied Member
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
-
Apr 30th, 2001, 06:25 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|