Results 1 to 4 of 4

Thread: RegSetValueEx

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Minnesota
    Posts
    24

    RegSetValueEx

    I just want to be able to modify a DWORD value in the Windows Registry. I have tried everyting I can think of to make it work. I know I have the declarations right, because I can change string values all day, and I can change the DWORD value, but it isn't the value that I wanted to change it to. Here are the pertinant lines in my code:
    Public Const REG_DWORD = 4
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Function SetKey(mkey As Long, subkey As String, kname As String, kval As String) As Long
    Dim hregkey As Long ' receives handle to the newly created or opened registry key
    Dim secattr As SECURITY_ATTRIBUTES ' security settings of the key
    Dim neworused As Long ' receives 1 if new key was created or 2 if an existing key was opened
    Dim hkval As Long ' value to set key to
    retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, "", 0, KEY_WRITE, secattr, hregkey, neworused)
    hkval = CLng(kval)
    retval = RegSetValueEx(hregkey, kname, 0, REG_DWORD, ByVal hkval, REG_DWORD)

    I hope someone can help.

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Have you had a look at

    www.vbworld.net/registry/

    ?

    VB Code:
    1. Public Sub SaveSettingLong(ByVal hKey As Long, ByVal _
    2. strPath As String, ByVal strValue As String, ByVal _
    3. lData As Long)
    4. Dim hCurKey As Long
    5. Dim lRegResult As Long
    6.  
    7. lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    8.  
    9. lRegResult = RegSetValueEx(hCurKey, strValue, 0&, _
    10. REG_DWORD, lData, 4)
    11.  
    12. If lRegResult <> ERROR_SUCCESS Then
    13. 'there is a problem
    14. End If
    15.  
    16. lRegResult = RegCloseKey(hCurKey)
    17. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Minnesota
    Posts
    24

    OMG!

    Well, I had looked at it, but the one thing I didn't notice was the "ByVal" wasn't there. I just changed:

    retval = RegSetValueEx(hregkey, kname, 0, REG_DWORD, ByVal hkval, REG_DWORD)

    to

    retval = RegSetValueEx(hregkey, kname, 0, REG_DWORD, hkval, REG_DWORD)

    and it worked like a charm. Thanks.

    For those interested, I've attatched the module to look at.

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    no probs

    It wasn't really me though :/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width