Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RegSetValueEx error

Posted on 2003-11-03
9
Medium Priority
?
1,984 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 400 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 1200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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