Solved

RegSetValueEx error

Posted on 2003-11-03
9
1,906 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:guidway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Assisted Solution

by:dc197
dc197 earned 100 total points
ID: 9674489
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
 
LVL 12

Author Comment

by:guidway
ID: 9674672
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
 
LVL 12

Author Comment

by:guidway
ID: 9674697
>>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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 100 total points
ID: 9675507
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
 
LVL 26

Accepted Solution

by:
EDDYKT earned 300 total points
ID: 9678325
0
 
LVL 12

Author Comment

by:guidway
ID: 9679031
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
 
LVL 12

Author Comment

by:guidway
ID: 9679038
that had no effect
0
 
LVL 12

Author Comment

by:guidway
ID: 9679564
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
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683177
Thanks,
It is cool to know you have solve the problem.

~ fantasy ~
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question