Results 1 to 15 of 15

Thread: Reg_dword

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Question

    Folks,

    With the following Module how do I add a Hexadecimal value? When I change REG_SZ to REG_DWORD, I get a binary value. I need to have a hex value. Please help

    aatwell
    --------------------------------------------------------

    Add to a Module


    code:--------------------------------------------------------------------------------
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    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
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const REG_SZ = 1

    Function RegQueryStringValue(ByVal HKEY As Long, ByVal strValueName As String)
    Dim lResult As Long
    Dim lValueType As Long
    Dim strBuf As String
    Dim lDataBufSize As Long

    On Error GoTo 0
    lResult = RegQueryValueEx(HKEY, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lResult = ERROR_SUCCESS Then
    If lValueType = REG_SZ Then
    strBuf = String(lDataBufSize, " ")
    lResult = RegQueryValueEx(HKEY, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
    If lResult = ERROR_SUCCESS Then
    RegQueryStringValue = StripTerminator(strBuf)
    End If
    End If
    End If
    End Function

    Public Function GetSettingEx(HKEY As Long, sPath As String, sValue As String)
    Dim KeyHand&
    Dim datatype&
    Call RegOpenKey(HKEY, sPath, KeyHand&)
    GetSettingEx = RegQueryStringValue(KeyHand&, sValue)
    Call RegCloseKey(KeyHand&)
    End Function

    Function StripTerminator(ByVal strString As String) As String
    Dim intZeroPos As Integer

    intZeroPos = InStr(strString, Chr$(0))
    If intZeroPos > 0 Then
    StripTerminator = Left$(strString, intZeroPos - 1)
    Else
    StripTerminator = strString
    End If
    End Function

    Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
    Dim KeyHand As Long
    Call RegCreateKey(HKEY, sPath, KeyHand)
    Call RegSetValueEx(KeyHand&, sValue, 0, REG_SZ, ByVal sData, Len(sData))
    Call RegCloseKey(KeyHand&)
    End Sub
    --------------------------------------------------------------------------------


    Usage:

    code:--------------------------------------------------------------------------------
    'Save a Value
    SaveSettingEx HKEY_CURRENT_USER, "Software\Myapp", "Testing", "Hello"


    'Get a value
    Retval = GetSettingEx(HKEY_CURRENT_USER, "Software\Myapp", "Testing")
    Print Retval

  2. #2
    Guest
    Make sure you have the constant right as well. Form what I see, you do not have the constant declared, nor is it changed in the code.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Question REG_DWORD DECLARED

    Megatron,

    Even when I do declare it, it doesn't work. What I am
    doing wrong? What value should the declaration take?
    I change every occurance of REG_SZ to REG_DWORD with
    a global replace and it doesn't work.

    code:--------------------------------------------------------------------------------
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const REG_DWORD = 1: 'what value should this be?


    And what should the usage be?

    SaveSettingEx HKEY_LOCAL_MACHINE, "Software\MyApp", "MyVal", 0

    Will this line add a hex value equal to zero into the reg?

    Please help me?

    aatwell

  4. #4
    Guest
    you got the constant wrong; it should be:
    Code:
    Const REG_DWORD = 4

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Angry I must have the usage wrong

    I tried using Public Const REG_DWORD = 4

    but it gives me a REG_DWORD entry with a binary value and it tells me it has an invalid DWORD value.

    I have tried the following usages:

    SaveSettingEx HKEY_LOCAL_MACHINE, "Software\MyApp", "MyVal", 0

    SaveSettingEx HKEY_LOCAL_MACHINE, "Software\MyApp", "MyVal", myval:' where i have tried declaring myval as (double,integer, long)

    SaveSettingEx HKEY_LOCAL_MACHINE, "Software\MyApp", "MyVal", "0"

    I am seriously exhausted with this Hexidecimal Registry Thing. Please help me find a solution. I am sure the problem is my own ignorance. But I'm trying hard to learn.

    aatwell

  6. #6
    Guest
    Sorry about that..Change the constant to 0 instead of 4.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Unhappy Tried 0,1,2,3,4

    I tried 0, 1, 2, 3, and 4 as the value for the constant and none worked.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Binary = Decimal = Hex

    It all depends on how you look at it...

    However, here's an example project: http://www.parksie.net/registry.zip
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Try...

    Try adding a binary value to the Windows 98 registry at:

    HKEY_LOCAL_MACHINE
    Network
    Logon
    MustBeValidated

    it doesn't like a binary value. The moment I put a hex value it works.

    Hence my dilemna. I must complete this program by April 18, 2001 for my employer.

    aatwell

  10. #10
    Guest
    Hmmm..I tried it when I changed the constant to 0 and it showed up as a dword value, e.g:

    84 58 49 32

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's binary...it should show up as 0x00000000 (0) or similar.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Unhappy Exactly

    Yup.

    I get the same kind of invalid value.
    It has to be 0x00000000 (0) in order
    for this to work, hence the dilemna.

    aatwell

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Cool Yaaahooo!

    I made some progress....

    I am getting a hex value now....

    I changed the following lines in the module

    From: Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
    To: Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As Long)

    and

    From: Call RegSetValueEx(KeyHand&, sValue, 4, REG_DWORD, ByVal sData, Len(sData))
    To: Call RegSetValueEx(KeyHand&, sValue, 4, REG_DWORD, ByVal sData, Len(sData))

    Then I used the usage

    SaveSettingEx HKEY_LOCAL_MACHINE, "Software\MyApp", "MyVal", 1

    only I got a strange hex value of

    6500c90f

    But at least it isn't a binary value and the machine recognizes it as a hex.

    Any clues on the rest of this puzzle.
    ======================================
    Coding C on Fedora Core 6 [gcc compiler]
    Coding VB on Windows XP [Visual Studio 6 compiler]

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Have a look at the code in my project...that works for strings & numbers.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    San Jose, CA
    Posts
    73

    Talking Parksie You Genius !!!!!!

    Thanks a lot. That code did the trick. I am now able to add valid HEX values to the registry.

    Not only is my hat off to you... but my head as well.


    Thnks.
    ======================================
    Coding C on Fedora Core 6 [gcc compiler]
    Coding VB on Windows XP [Visual Studio 6 compiler]

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