|
-
Nov 20th, 2001, 05:16 AM
#1
Thread Starter
Junior Member
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.
-
Nov 20th, 2001, 05:25 AM
#2
Conquistador
Have you had a look at
www.vbworld.net/registry/
?
VB Code:
Public Sub SaveSettingLong(ByVal hKey As Long, ByVal _
strPath As String, ByVal strValue As String, ByVal _
lData As Long)
Dim hCurKey As Long
Dim lRegResult As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
lRegResult = RegSetValueEx(hCurKey, strValue, 0&, _
REG_DWORD, lData, 4)
If lRegResult <> ERROR_SUCCESS Then
'there is a problem
End If
lRegResult = RegCloseKey(hCurKey)
End Sub
-
Nov 20th, 2001, 05:59 AM
#3
Thread Starter
Junior Member
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.
-
Nov 20th, 2001, 06:05 AM
#4
Conquistador
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|