|
-
September 6th, 2001, 08:58 AM
#1
Int to DWORD
How do I convert an integer value to a DWORD value?
-
September 6th, 2001, 09:52 AM
#2
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)
-
September 6th, 2001, 10:15 AM
#3
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?
-
September 6th, 2001, 11:15 AM
#4
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?
-
September 6th, 2001, 12:24 PM
#5
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
-
September 6th, 2001, 01:19 PM
#6
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...?????
-
September 6th, 2001, 03:43 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|