|
-
Mar 7th, 2001, 11:21 AM
#1
Thread Starter
Lively Member
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
-
Mar 7th, 2001, 03:47 PM
#2
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.
-
Mar 7th, 2001, 10:23 PM
#3
Thread Starter
Lively Member
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
-
Mar 8th, 2001, 03:35 PM
#4
you got the constant wrong; it should be:
Code:
Const REG_DWORD = 4
-
Mar 9th, 2001, 08:21 AM
#5
Thread Starter
Lively Member
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
-
Mar 9th, 2001, 03:23 PM
#6
Sorry about that..Change the constant to 0 instead of 4.
-
Mar 9th, 2001, 03:27 PM
#7
Thread Starter
Lively Member
Tried 0,1,2,3,4
I tried 0, 1, 2, 3, and 4 as the value for the constant and none worked.
-
Mar 9th, 2001, 03:40 PM
#8
Monday Morning Lunatic
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
-
Mar 9th, 2001, 04:09 PM
#9
Thread Starter
Lively Member
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
-
Mar 9th, 2001, 06:27 PM
#10
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
-
Mar 9th, 2001, 06:29 PM
#11
Monday Morning Lunatic
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
-
Mar 9th, 2001, 07:09 PM
#12
Thread Starter
Lively Member
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
-
Mar 9th, 2001, 09:16 PM
#13
Thread Starter
Lively Member
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]
-
Mar 10th, 2001, 05:09 PM
#14
Monday Morning Lunatic
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
-
Mar 12th, 2001, 02:12 PM
#15
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|