CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Int to DWORD

  1. #1
    Join Date
    Apr 2001
    Posts
    95

    Int to DWORD

    How do I convert an integer value to a DWORD value?


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Int to DWORD

    In VB a Long is the equivelent of a DWORD so use:



    Dim I as int
    dim L as long

    I = 10
    L = Clng(i)





  3. #3
    Join Date
    Apr 2001
    Posts
    95

    Re: Int to DWORD

    Ok Say I = 0 and we add it to the registry as a DWORD value. The decimal value of the DWORD is now 48. Now we want to retrieve it from the regsitry as long and then convert it to Integer using CInt. The value is still 48. What am I doing wrong?


  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Int to DWORD

    0 should = 0 no matter if it's an int, long, or any other numeric data type. Are you sure you are writing the correct value to the registry? Could you post the code?


  5. #5
    Join Date
    Apr 2001
    Posts
    95

    Re: Int to DWORD



    ' These are the basic funcions that write to the
    ' registry... additional functions are used to open keys
    ' Where ValueName = the registry value name and
    ' Setting = the value we are writing to the registry.

    ' Result is the result of previously opening a key

    public Function SetDWORDValue(ValueName as string, Setting as Long) as Long
    Dim RetVal as Long

    RetVal = RegSetValueEx(Result, ValueName, 0&, REG_DWORD, Setting, 4&)
    SetDWORDValue = RetVal
    End Function

    public Function GetDWORDValue(ValueName as string) as Long
    Dim RetVal as Long
    Dim lBuffData as Long

    RetVal = RegQueryValueEx(Result, ValueName, 0&, REG_DWORD, lBuffData, 4&)
    GetDWORDValue = lBuffData
    End Function

    ' This goes in Form_QueryUnload
    SetDWORDValue "UseGlobal", CLng(chkGlobal.Value)

    ' and this in Form_Load
    chkGlobal.Value = CInt(GetDWORDValue("UseGlobal"))





    Thanks for your help DSJ


  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Int to DWORD

    This code is working for me as expected...????


    option Explicit
    private 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
    private Const REG_DWORD = 4
    private Const HKEY_CURRENT_USER = &H80000001
    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

    public Function SetDWORDValue(ValueName as string, Setting as Long) as Long
    Dim RetVal as Long
    RetVal = RegSetValueEx(HKEY_CURRENT_USER, ValueName, 0&, REG_DWORD, Setting, len(Setting))

    SetDWORDValue = RetVal
    End Function

    public Function GetDWORDValue(ValueName as string) as Long
    Dim RetVal as Long
    Dim lBuffData as Long

    RetVal = RegQueryValueEx(HKEY_CURRENT_USER, ValueName, 0&, REG_DWORD, lBuffData, len(lBuffData))
    GetDWORDValue = lBuffData
    End Function


    private Sub Command1_Click()
    chkGlobal.Value = CInt(GetDWORDValue("UseGlobal"))
    End Sub

    private Sub Command2_Click()
    SetDWORDValue "UseGlobal", CLng(chkGlobal.Value)
    End Sub





    Don't know what to tell you...?????


  7. #7
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Int to DWORD

    48 is the ascii value for a Numeric 0 so maybe that came into play in your first complaint.
    If you passed it a numeric 0 instead of CHR(0), this would account for the error.

    John G

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

Featured