RegSetValueEx error

I'm trying to write data to the registry using this function and it keeps returning error code 1450 (insufficient resources). Anyone know what would cause this?

My function looks like:

Public Function SaveSetting(ByVal Section as String, ByVal Key As String, ByVal Setting as String) as Boolean

   Dim nRet as Long
   Dim hKey as Long
   Dim nResult as Long
   
   nRet = RegCreateKeyEx(HKEY_CURRENT_USER, SubKey(Section), 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, hKey, nResult)

   If nRet = ERROR_SUCCESS Then
      If Key = "*" then Key = vbNullString
      nRet = RegSetValueEx(hKey, Key, 0&, REG_SZ, ByVal Setting, Len(Setting)) '<- here's where I get the error
      Call RegCloseKey(hKey);
   End If
   SaveSetting = (nRet = ERROR_SUCCESS)
End Function

any ideas why I'm getting this error. My virtual disk space is at 1.5GB and I'm sure I have enough memory (1GB RAM), what other resources could be gone? I have nothing else running that uses a lot of resources.
LVL 12
guidwayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dc197Commented:
I use the String and Long versions:


 Public Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
   
 Public Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
   



Public Function PutRegKeyEx _
    ( _
        ByVal hKey As Long _
        , sValueName As String _
        , lType As Long _
        , vValue As Variant _
    ) As Long
    DoEvents
   
    Dim lValue As Long
    Dim sValue As String
    Select Case lType
    Case StringKey
        sValue = vValue & Chr$(0)
        PutRegKeyEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
    Case DoubleWord
        lValue = vValue
        PutRegKeyEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
    End Select
End Function

0
guidwayAuthor Commented:
hi dc197,

thanks for the response, I tried that just now and got the same error. I have successfully been able to read from the registry (manually and programmatically) and I can write values to it manually using regedit but not programmatically. Anytime I try to use RegSetValueEx (or RegSetValueExString) I get the same error code... I'm on a Win2k SP3 O.S. using VB6SP5 so I'm doubtful it is a bug. It's frustrating that I can't get more info about what is causing the error. It is too generic... thanks again

guid
0
guidwayAuthor Commented:
>>so I'm doubtful it is a bug<<

let me clarify that statement. I mean I doubt it is a bug in Microsoft's code base since I have the latest service pack. I didn't mean I was doubtful it was a bug on my part. In fact, I'm about 95% sure it is since I seem to be the only one on the web having this error. ;)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fantasy1001Commented:
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long

Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Save a string to the key
    RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    'close the key
    RegCloseKey Ret
End Sub

Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
    'close the key
    RegCloseKey Ret
End Sub

Private Sub Command1_Click()
    Dim strString As String
    'Ask for a value
    strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
    If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
        MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
        Exit Sub
    End If
    'Save the value to the registry
    SaveStringLong HKEY_CURRENT_USER, "keyitem", "BinaryValue", CByte(strString)
End Sub


~ fantasy ~
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guidwayAuthor Commented:
I've tried it everyway so far and everytime it gets to that line it gives the same error. I've even rebooted the computer to make sure it wasn't too many resources. I'm going to try increasing the size of the registry limit in win2k and see if that helps.
0
guidwayAuthor Commented:
that had no effect
0
guidwayAuthor Commented:
just tried the code for EDDYKT again and then it started working. I guess it may have been a copy error when I tried copying the code over. Anyway, I appreciate everyone's effort.

300 pts to EDDYKT
100 pts for fantasy1001
100 pts for dc197

thanks again
guid
0
fantasy1001Commented:
Thanks,
It is cool to know you have solve the problem.

~ fantasy ~
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.