Unusual results writing longs to Registry (please help) 
Author Message
 Unusual results writing longs to Registry (please help)

Using Win API functions, I made some procedures for reading and writing to
the Registry. Writing strings works, but when I try to write a long integer,
the results are weird.

1 is written as 1,694,550,287
10 is written as 73,729,193
100 is written as 90,832,943
and numbers below 1 aren't allowed for some reason (error 87,
errRegInvalidParameters is returned)

I'm TOTALLY baffled. Much of the code comes from a KB article (Q145679), but
I've reshaped it in several places. I haven't made the example exactly as it
is, but I can't see much difference between its and my code...

Here's the relevant code:

Public Const Success = 0
Public Const RegString = 1
Public Const RegLong = 4

Public Sub RegWriteValue(sPath As String, _
                         sValueName As String, _
                         vData As Variant, _
                         lType As Long, _
                         Optional lRoot As Long)
On Error GoTo Exceptions
    If (lRoot = 0) Then lRoot = hKeyLocalMachine
    Dim hKey As Long
    hKey = GetKey(lRoot, sPath)
    Dim lReturn As Long
    Select Case lType
    Case RegString
        Dim sData As String
        sData = Format$(vData) & Chr$(0)
        lReturn = RegSetValueExString(hKey, sValueName, 0&, _
                                      RegString, sData, _
                                      Len(sData))
    Case RegLong
        Dim lData As Long
        lData = CLng(vData)
        lReturn = RegSetValueExLong(hKey, sValueName, 0&, _
                                    RegLong, lData, RegLong)
    Case Else
        Err.Raise 5 'invalid call
    End Select
    If (lReturn <> Success) Then Err.Raise lReturn

Cleanup:
    On Error Resume Next
    RegCloseKey hKey
    Exit Sub

Exceptions:
    If (hKey <> 0) Then RegCloseKey hKey
    Err.Raise (Err.Number)
End Sub

Private Function GetKey(lRoot As Long, _
                        sPath As String) As Long
On Error GoTo Exceptions
    Dim lAPIReturn As Long
    Dim hKey As Long
    Dim lDisposition As Long
    Dim sa As SECURITY_ATTRIBUTES
    lAPIReturn = RegCreateKeyEx(lRoot, sPath, hKey, vbNullString, _
                                regOptionVolatile, KEY_ALL_ACCESS, _
                                sa, hKey, lDisposition)
    If (lAPIReturn = Success) Then
        GetKey = hKey
    Else
        Err.Raise errKeyNotFound
    End If
    Exit Function
Exceptions:
    Err.Raise (Err.Number)
End Function



Sat, 15 Jul 2000 03:00:00 GMT  
 Unusual results writing longs to Registry (please help)

Never mind. My declaration was wrong. I had a ByVal where I shouldn't
have...yadda yadda yadda.



Sat, 15 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Unusual results writing longs to Registry (please help)

2. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

3. Text boxes - unusual editing facilities (please help!)

4. Unusual VB Error - Help Please

5. Registry Problems Help Please! - registry.bas (0/1)

6. Registry Problems Help Please! - registry.bas (1/1)

7. Cancelling file writing process during long writes

8. Reading Registry value, help me please,please

9. Writing a VBS file which reads and writes to the registry

10. Can anyone HELP me PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE

11. Help: read or write to the registry

12. writing to registry..HELP

 

 
Powered by phpBB® Forum Software